使用javascript将表单提交到iframe目标中
Submit form into an iframe target with javascript
我正试图打开一个带有POST和iframe参数的网页。但是当提交时,父页面会被重新加载,并且URL没有打开到iframe:中
<head>
<title>iframe Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
iframe {
display: block; /* iframes are inline by default */
background: #000;
border: none; /* Reset default border */
height: 90vh; /* Viewport-relative units */
width: 90vw;
}
</style>
</head>
<body>
<form id="myForm" method="post" action= "http://127.0.0.1/myWeb" target="myIframe">
<input type = "hidden" name="param1" value="param1value">
<input type = "hidden" name="param2" value= "param1value">
</form>
<a href="" onClick="postLogin();" >Send to iframe</a><br />
<script laguaje="javascript">
function postLogin() {
var form = document.getElementById("myForm");
form.submit();
}
</script>
<iframe src="" name="myIframe" id="myIframe">
<p>iframes are not supported by your browser.</p>
</iframe>
</body>
</html>
刷新页面的是锚点标记。您可以使用event.preventDefault()
。
更改锚定标记并添加事件参数。
<a href="" onClick="postLogin(event);" >Send to iframe</a>
在Javascript函数postLogin
中添加preventDefault()
事件方法:
function postLogin(event) {
var form = document.getElementById("myForm");
form.submit();
event.preventDefault();
}
编辑:
或者,您可以使用不带postLogin
函数的<button>
而不是<a>
。
<form id="myForm" method="post" action= "http://127.0.0.1/myWeb" target="myIframe">
<input type = "hidden" name="param1" value="param1value">
<input type = "hidden" name="param2" value= "param1value">
<button type="submit">Send to iframe</button>
</form>
相关文章:
- 使用javascript将表单提交到iframe目标中
- 在 iframe 中指定全局变量名称时,表单目标会中断
- html表单操作跨域目标iframe
- iFrame 不会扩展到完整的内容高度,即使有 jQuery 脚本以它为目标
- 将 href 加载到 iframe,但以父窗口为目标
- 在 HTA 中将元素目标发送到 iframe
- 使用目标从弹出窗口在 safari 中发布和重定向 iframe
- 目标窗口.打开iframe
- 将位于子页面中的主页中的iframe作为目标
- php或javascript中不同页面的目标iframe
- iframe上的跨域javascript,而无法访问目标iframe
- 我怎么能有一个iframe来显示目标页面及其所有内容's元素的比例为50%
- 发布到iframe目标:无法从iframe获得响应
- 如何使用Javascript postMessage将不同协议的iframe外部的元素作为目标
- YouTube API目标(多个)现有iframe
- 从VBulletin调用外部动态链接>需要在基本目标iFrame中打开的链接
- 使用javascript将Iframe作为目标,并在内部使用GET方法的php
- 目标主窗口从iframe在HTML中
- 删除iframe link中的目标属性
- jQuery ajax和php iframe.形成目标问题