Can I block _parent attribute?


I was wondering if is it possible to prevent a form in iframe submitting to it’s _parent page and force it to submit to iframe instead?

Please see my example below:


Content of page 1

<iframe src="http://server-b/form.html" width="450" height="500">
  <p>Your browser does not support iframes.</p>



<form action="http://server-a/landing.cgi" target="_parent">
<input type="hidden" name="field1" value="val1" />
<input type="submit" value="Submit" />

At the moment when form is submitted, output of http://server-a/landing.cgi overwrites http://server-a/page1.html. What I a am looking for is some clever JavaScript to block target=“_parent” attribute somehow and force http://server-a/landing.cgi to stay in iframe.


Could you give a name to the iframe, and give that name to the target attribute? No scripting required, or needed even.

Hi Paul, many thanks for your reply.

Unfortunately I have no control over http://server-b/form.html

I can only manage http://server-a/

So my idea was to use ‘onbeforeunload’ or similar to solve this problem. Not sure how this could be exactly done though.

onbeforeunload only allow you to show a message to the user, where they can choose to stay on the page or allow the new page to load.
For an example, see: onbeforeunload Demo

I don’t think that web browsers allow you to have the control that you seem to need, over an iframe from another domain.