【问题标题】:Using click() on the hidden submit button inside iframe works in FF and Chrome but not IE and Opera在 iframe 内的隐藏提交按钮上使用 click() 适用于 FF 和 Chrome,但不适用于 IE 和 Opera
【发布时间】:2014-02-14 02:48:13
【问题描述】:

在我网站的父页面上,我使用了一个 iframe(带有一个显示:无提交按钮),其中包含一个文件上传表单,以允许用户上传个人资料图片而无需重新加载父页面。该方法适用于 Chrome 和 FF,具有以下任一功能('NoReloadiframe' 是 iframe 的 id,'iframePicButton' 是显示的 id:隐藏 iframe 的图片上传表单中的无提交按钮):

function HiddenPicButton() {
    document.getElementById('NoReloadiframe').contentWindow.document.getElementById('iframePicButton').click();
}

function HiddenPicButton() {
    window.frames['NoReloadiframe'].contentWindow.document.getElementById('iframePicButton').click();
}

这是 iframe 中表单的代码:

<form action="#" enctype="multipart/form-data" method="post" id="HiddenUserPicForm">
    <button type="submit" name="iframepicbutton" id="iframePicButton" style="display:none">    
    </button>
    <input type="file" name="ifrpic" id="ifrfile">
</form>

简单来说,点击父页面上的文件上传按钮调用HiddenPicButton(),它点击iframe内的隐藏按钮,文件上传,无需重新加载父页面。

然而,隐藏按钮点击不会在 Opera 或 IE 中发生(chrome 和 FF 完全按预期工作)。有关如何解决此问题的任何指示?作为备份,我将恢复到最初使用的页面重新加载方法或尝试使用 Javascript 来检测浏览器(使用此处显示的方法:Browser detection in JavaScript?)用户正在导航并隐藏 IE 的 iframe 提交按钮和 Opera 使用 onLoad 函数。

【问题讨论】:

  • 为什么不直接在表格上拨打submit()
  • 试试这个...谢谢你的建议

标签: javascript forms iframe


【解决方案1】:

试试:

function HiddenPicButton() {
  document.getElementById('NoReloadiframe').contentWindow.document.forms[0].submit();
}

【讨论】:

  • 感谢您的建议...该表单现在无法在 Chrome 中提交...我会在这方面做更多的工作..
  • 如果将正确的 url 设置为表单的操作属性会发生什么?
  • 抱歉...我刚刚重新检查了我的第一个功能...实际上在所有 4 个浏览器中都可以工作...不知道为什么我点击了上传按钮 20 次,但之前在 Opera 上却没有工作和 IE .....第二个功能不适用于所有浏览器..
猜你喜欢
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多