SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I block _parent attribute?

    Hi,

    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:

    http://server-a/page1.html:
    Code HTML4Strict:
    <html><body>
    Content of page 1
     
    <iframe src="http://server-b/form.html" width="450" height="500">
      <p>Your browser does not support iframes.</p>
    </iframe>
     
    </body></html>

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

    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.

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Could you give a name to the iframe, and give that name to the target attribute? No scripting required, or needed even.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Alan22 View Post
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •