【问题标题】:JavaScript not working inside iframe in FirefoxJavaScript 在 Firefox 的 iframe 中不起作用
【发布时间】:2013-03-30 11:46:02
【问题描述】:

我正在使用 iframe 加载带有表单的页面。使用 javascript 覆盖表单操作。 javascript 表单操作在 IE 和 Chrome 中运行。但在 Firefox 中,javascript 不起作用,表单正在提交给http://example.com/index.php

代码如下:

<script language='Javascript' type='text/JavaScript'>
function submitFunction() {
document.Insert.action = 'http://example.com/page2.php';
return true;
}
</script>

<FORM ACTION='http://example.com/index.php' METHOD='POST' ENCTYPE='x-www-form-urlencoded' name='Insert' id='Insert' autocomplete='off' onsubmit='return(submitFunction())'>

<input name='num' SIZE='45' MAXLENGTH='45'>

<input name='Submit' type='submit'/>
</FORM>

提前致谢。

【问题讨论】:

    标签: javascript firefox iframe


    【解决方案1】:

    改变

    document.Insert.action = 'http://example.com/page2.php';
    

    document.getElementById('Insert').action = 'http://example.com/page2.php';
    

    但是在onsubmit中更改表单的action URL似乎有点奇怪。您也可以从一开始就定义它。

    【讨论】:

    • 我想隐藏 url,所以我将它加载到 iframe 中。提交按钮将在鼠标悬停时显示表单操作 url。问题是当它加载到 iframe 中时。
    • @user1690835:让用户看到即将发生的事情是一件好事。强烈建议专注于有用的功能,而不是向用户隐藏东西。
    猜你喜欢
    • 2012-11-27
    • 2019-01-09
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多