Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2003
    Location
    Sydney Australia
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enforcing Validation check within iframe

    Hi,

    I have a HTML Page with a couple of buttons across the top, which determine what source appears in an iframe beneath. In one of the pages within the iframe, I'm validating input - when an error occurs, I simply wish the user to be prevented from leaving this page until the error is fixed. However, if I click one of the buttons across the top in the main html page, then I get an error message, and the source of the iframe is changed regardless.

    Is there a way to enforce the iframe source to remain, even if I trigger an event from outside of it?

    many thanks,

    Brendon

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    simple example
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    var Lk=true;
    
    function CngSRC(url){
     if (!Lk){
      document.getElementById('MyiFrame').src='http://www.js-examples.com';
     }
    }
    
    //-->
    </script>
    </head>
    
    <body>
    <input type="button" name="" value="Change URL" onclick="CngSRC();" >
    <iframe src="mm1.htm" id="MyiFrame" name="MyiFrame" frameborder="1"></iframe>
    
    </body>
    
    </html>
    mm1.htm
    Code:
    <html>
    <head>
    
    </head>
    
    <body  >
    
    <input type="button" name="" value="Lock SRC" onclick="parent.Lk=true; ">
    <input type="button" name="" value="Un Lock SRC" onclick="parent.Lk=false; ">
    <br>
    
    </body>
    </html>
    set Lk true or false in your validation


  •  

    Posting Permissions

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