首页 > 解决方案 > 谷歌浏览器中没有间歇性地提交表单

问题描述

我有一个包含 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&amp;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 正在提交表单并且一切正常。

有人能告诉我为什么会出现这个问题,或者至少是这个问题的替代解决方案吗?我希望提供所有必需的信息。如果您需要任何其他详细信息,请告诉我。

标签: javascriptjqueryhtmlformsgoogle-chrome

解决方案


加载about:blankiframe 或在 iframe 的onload功能上提交表单。

可能是srciframe 中给出的图像加载中断了表单提交。


推荐阅读