Friday 15 April 2011

javascript - recognizing actions on an iframe -


Then I have an iframe, and I want to be able to do something like a warning Whenever a specific button is clicked in the IFrame. But the following code does not work

  $ ('. Class_name'). Click (function () {warning ('click');}); Actually, it even gets used to  alerts  when iframe is clicked (which is the same code as above, but where  .class_name   iframe .  

I looked through the solution, and it still does not work!

This problem is very much

So my question is: Why is anything inside the iframe, as well as the actual iframe clicked, why not believe Jquery ?

Edit:

I understand that I can not communicate with an iframe on a different domain, so my JSWald does not work ... but It does not work on the site where I am hosting it as iframe on the same domain ...

If your iframe Coming from a different domain, as in your Belal, there is no access to your Javascript code. Sorry, at all! Sorry!

As @Max Points, you can use the post message () or the URL fragment to communicate with another iframe For the main, if is the code in iframe to handle this communication from that side.

With an iframe from tumblr.com, you can see your document to see if he talks about it, using this page in iframe and communicating with it in domain blocking .

Now if you are talking about an iframe from the same domain as your page, then it is easy. Looking at the iframe element in a variable named myframe , you get the window to get myframe.contentWindow You can use and get your document object to get myframe.contentWindow.document . From there you can meet your needs. For example:

  var $ myframe = $ ('# myframe'), myframe = $ myframe [0], myframewin = myframe.contentWindow, myframedoc = myframewin.document; $ (Myframedoc) Fend ('A'). ('Click', function () {warnings ('clicked!');});   

You may have some trouble using a copy of jQuery in the main page to use things in the iframe, but there should be better luck with the latest versions. The worst case is that you can use native DOM events and methods for this but works in jQuery.

This Bella uses the document. Write to insert content in iframe, but the jQuery code that reaches the frame will be identical in any way. Surely one thing to see is that the IRM is fully loaded when you try to access it.

I Think you event on the iframe element in the page containing , but the worst position is setTimeout ( ) or setInterval () and wait for the elements that you are looking for to be available.

No comments:

Post a Comment