Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

html - Firefox form targeting an iframe is opening new tab

<form method="post" target="take_the_reload">

    ...

</form>


<iframe class="hide_me" name="take_the_reload"></iframe>

My issue is as follows:

I have a form that needs to be prevented from refreshing the page it is located on when it is submitted. To combat this issue, I have been using an empty iframe as the target for the form. This works exactly as expected in Chrome (v12.0.742) but fails in Firefox (v6.0).

What happens in Firefox, is that the iframe is opened in a new tab upon form submission, which is obviously not what I want.

I have found some related posts, but none address my particular situation and their solutions do not work.

Unfortunately, the work is on a proprietary system in a private network so I can not just simply provide a link.

I have also tried using a frame as opposed to an iframe as an answer to a related topic was that using iframes in such a manner is deprecated. But the results are identical.

Also the iframe is hard-coded into the page in the sense that it is not dynamically added with JavaScript. Finally, like I said earlier, this works flawlessly in Chrome, but fails to work at all in Firefox. IE is not a concern and so any non-IE-friendly solutions are welcome!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This might sound stupid but did you try giving the iframe an id the same as the name attribute? This seems to solve some problems relating to forms.

<form method="post" action="link/to/post/to" target="take_the_reload">

    ...

</form>

<iframe id="take_the_reload" name="take_the_reload"></iframe>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...