javascript - 谷歌浏览器中没有间歇性地提交表单
问题描述
我有一个包含 iFrame 的网页。此网页会自动向第三方 url 提交表单,该 url 会在 iFrame 中加载内容。我目前正在通过 jQuery 在 document.ready() 上自动提交表单,看起来 chrome 没有间歇性地提交此表单。
以下是我网页中的示例 html。
<form id="form_init" target="myFrame" action="https://somethirdpartyurl.com/req.jsp?queryParam=value" method="post" class=" edit accessAid">
<input name="_cs" id="_cs2" value="blah" type="hidden">
<input name="cs" id="cs2" value="blah" type="hidden">
<input type="hidden" name="howdy" value="oneMoreBlah">
<input type="hidden" name="myUrl" value="http://localhost:8000/myapp?_eventId=processing&sessionId=123">
<input type="hidden" name="MD" value="1234567891234567">
<div id="submit_button">
<p>Attention: This form can't be displayed because JavaScript is disabled in your browser.</p>
<p class="buttons">
<span class="buttonAsLink">
<input type="submit" name="" class="button autoSubmit" value="Click here to continue">
</span>
</p>
</div>
</form>
<iframe name="myFrame" id="myFrame" width="625px" height="480px" frameborder="0" marginheight="0" scrolling="auto" src="https://www.mywebsite.com/grey_spacer.gif"></iframe>
<script src="http://www.localhost:8000/myapp/webstatic/js/loadFrame.js" type="text/javascript"></script>
下面是 loadFrame.js 文件的片段。
$(document).ready(function() {
$("#submit_button").length && ($("#submit_button").hide(), $("#submit_button input").hasClass("autoSubmit") && $("#submit_button input")[0].form.submit());
});
请注意,$("submit_button input")[0].form.submit()
命令之前的所有条件都是成功的。我已通过控制台日志确认。
我现在面临的问题是,chrome 没有间歇性地提交上述表格。此问题在其他浏览器(如 FireFox 和 Safari)中不存在。
一个观察结果是,当我打开开发人员工具并检查禁用缓存选项时,大多数时候表单都没有提交。如果我取消选中该选项,则主要是提交表单。(大多数时候都是这样,不是全部)
另一件事是,当我$("submit_button input")[0].form.submit()
在控制台中手动执行相同的命令时,chrome 正在提交表单并且一切正常。
有人能告诉我为什么会出现这个问题,或者至少是这个问题的替代解决方案吗?我希望提供所有必需的信息。如果您需要任何其他详细信息,请告诉我。
解决方案
加载about:blank
iframe 或在 iframe 的onload
功能上提交表单。
可能是src
iframe 中给出的图像加载中断了表单提交。
推荐阅读
- c# - 知道为什么数组的第二个元素没有被赋值吗?
- php - 使用 php 从未知远程服务器读取“.txt”文件时有哪些安全问题?
- react-native - 无法访问 react-navigation v3 选项卡导航器中的 redux 道具(出现错误 this.props。
不是函数) - javascript - 在数组上查找对象的索引
- java - @EnableWebMvc 上的 Spring 条件 bean
- phpstorm - 我可以在 PhpStorm 2019.1 中使用常用代码片段吗?
- html - 我想防止 HTML 元素相互移动并让它们重叠
- python - 如何修复 conda 的“ModuleNotFoundError”?
- python - Keras:如何将两个层而不是 Elementwise 组合成更大的形状
- c# - 鼠标轴基于位置,而不是移动