【发布时间】:2017-09-19 10:25:51
【问题描述】:
我正在尝试向 iframe 提交一个表单,这两个 iframe 都是在我的项目中使用 javascript 动态构建的。
<script>
document.querySelector('iframe').setAttribute('id', iframeId);
document.getElementById(iframeId).setAttribute('name', target);
document.getElementById(iframeId).setAttribute('width', width);
document.getElementById(iframeId).setAttribute('height', height);
document.querySelector('form').setAttribute('id', id);
document.getElementById(id).setAttribute('target', target);
document.getElementById(id).setAttribute('action', actionURL);
document.getElementById(id).submit();
<script>
这就是它稍后在浏览器 Web Inspector 中的外观。
<iframe id="my_frame" name="my_frame" width="700" height="400">
<p>Your browser does not support iframes.</p>
</iframe>
<form id="my_form" target="my_frame" action="http://localhost:8080/MyProject/loadService" method="POST" style="display: none;">
<input type="hidden" name="userId"/>
<input type="hidden" name="locale"/>
</form>
这在 Firefox 中对我很有效,但在 Chrome 中它会打开一个新标签。我尝试了here 给出的解决方案,但没有解决问题。任何人都可以建议缺少什么吗?
【问题讨论】:
标签: javascript html google-chrome iframe