javascript - iFrame Validation -


I currently have an iframe inside my main page that contains several checkboxes, which need to take action before leaving the iframe That is, if the user starts checking checkboxes and halfway, then they click back to the main page, i.e. except for the iframe, I want to be able to net / validate that they have left the iframe And they are indicated with the message informing it, say with a "note: you will lose all the data entered here - leave: yes / no?" Type message.

Any help / website will be appreciated.

Thanks Tony

It looks like 4guys article you need. It talks about onbeforeunload event. There is also some awesome stack overflow here, which is also about it.


It appears that in reality, an IFrame does not actually fire. Bugger!

Here is some sample code, although this should work. This will only work if you are in the same domain, otherwise iFrame will have to stop talking to your parents.

I have not tested them in many browsers so that YMMV is there.

You have two options here, depending on where you want to put the prompts for change logic.

If there is a change in the option , the iframe is included to the original window.

Parents window JavaScript:

  window. Onbeforeunload = closeIt; Var changes = false; Close the function () {if (change) {return "yo, change, save them?"; }} Something changed () {changes = true; };  

IFrame javascript:

  $ (function () {$ ('input'). Change (parent.somethingChanged);});  

Option 2 includes iframe controlling the on-line unloaded of the parent window

Parent Window Javascript:

< P> none: -)

Iframe javascript:

  $ (function () {parent.window.onbeforeunload = myCloseIt; $ ('Input') .change (some change);}); Var changes = false; Function myCloseIt () {if (change) {return "yo, change, save them?"; }} Something changed () {changes = true; };  

In either option, the naive change variable can be extended up a bit, perhaps using techniques from the 4guys article to see if Actually


If they are on separate domains, but you are in charge of "both sides" of HTML, then there are still some options, they are just tough.

There is a library which uses post message and the location is the black magic of secret magic to communicate the hash and cross site.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -