简体   繁体   中英

JavaScript not working inside iframe in Firefox

I am using an iframe that loads a page with a form. The form action is overridden using javascript. The javascript form action is working in IE and Chrome. But in Firefox the javascript is not working and the form is getting submitted to http://example.com/index.php

The code is given below:

<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>

Thanks in advance.

Change

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

to

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

But it seems a little strange to change the action URL of the form in the onsubmit. You could as well have it defined from the start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM