I want to show a page inside of an iframe, it will be running on the same server as my application, I want to fire an event whenever a certain page appears by locating an element on the page and then add a button next to that element with some functionality. Is that feasable? how would I put an event on the iframe so that whenever an item with that class is created it runs my code?
Asked
Active
Viewed 80 times
1
-
same server....also the same domain? – Dr.Molle Oct 05 '12 at 18:16
-
It is possible, you would just need to listen to the iframe's load event then inspect it's contents and make your modifications. – Kevin B Oct 05 '12 at 18:16
-
yes, it's running in the same tomcat instance. To be more specific I'm doing this with the drools/guvnor interface. Trying to do it without modifying the drools war itself. – Rocky Pulley Oct 05 '12 at 18:18
-
just a note... same tomcat instance doesn't necessarily mean same-domain. Same domain means same subdomain, primary domain, port, and protocol. – Kevin B Oct 05 '12 at 18:33
-
I think it is doable as long as the iframe page is from the same domain, using http://api.jquery.com/contents/ there are questions like this before but I cannot find the right one atm. EDIT - found it http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe see the one after checked. I believe you should be able to bind events using the same method – Huangism Oct 05 '12 at 18:47
1 Answers
0
See here jQuery/JavaScript: accessing contents of an iframe
Assuming same domain, taken from the other answer
$("#iFrame").contents().find("#someDiv").removeClass("hidden");
// gets the element
$("#iFrame").contents().find("#someDiv")
// so I assume this would work
$("#iFrame").contents().find("#someDiv").on(...)