html - 如何将表单数据发送到同一网页中的 iframe src
问题描述
我有一个带有一个输入的表单,您可以在其中键入网站的 URL,然后 URL 应该被发送到同一网页上的 iframe,它应该 iframe 的 URL。这是我当前在URL 输入中键入http://example.com时得到的代码,它给了我错误,cannot GET /my_frame%22?Url=http%3A%2F%2Fexample.com
<html>
<head>
<title>Form Iframe Demo</title>
</head>
<body>
<form action=my_frame" >
<input type="text" name="Url" value="http://" />
<input type="submit" />
</form>
<--Iframe should receive url from the form and then Iframe it -->
<iframe name="my_frame" src="Url" width="860px">
</iframe>
</body>
</html>
试过搞砸它,但它让我陷入困境
我希望它有一个http://example.com的 iframe,但我收到一个错误
解决方案
<html>
<head>
<title>Form Iframe Demo</title>
</head>
<body>
<input type="text" name="Url" id="url" value="https://j-mrad.github.io/" />
<button onClick="LoadURL();" >Load URL</button>
<br><br>
<iframe id="my_frame" src="https://www.w3schools.com" width="600px" height="500px">
</iframe>
<script type="text/javascript">
function LoadURL(){
document.getElementById("my_frame").src=document.getElementById("url").value;
}
</script>
</body>
</html>
推荐阅读
- python - 从 GMT 到 UTC-4 的时区转换
- javascript - Javascript:如何将日期时间从 yyyy-mm-ddThh:mm:ss 转换为 m/d/yyyy h:mm am/pm
- django - Querying the images of an product in django
- javascript - JavaScript 类:从对象的函数属性中访问方法
- hybris - 在hybris tomcat中部署war文件
- php - 在 Woocommerce 中应用特定优惠券时隐藏免费送货
- java - 降低 ND4J 中的数字准确性
- pyspark - 使用追加写入模式将新数据写入现有 parquet 文件
- windows - Windows kernel32.dll 仅程序集绘制像素
- google-apps-script - OnEdit 功能不适用于共享用户