javascript - Intercept Link Clicks from Frame -
i have old fashion page uses frameset containing top frame , bottom frame. frameset defined in "index.html" , code follows:
<html> <head> <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script> $(document).ready(function(){ $('#mainframe').ready(function() { $('#mainframe a').live('click', function() { alert('u click'); return false; }); }); }); </script> </head> <frameset id="main" rows="125,*" cols="*"> <frame src="header.html" name="headerframe" id="headerframe" /> <frame src="main.html" name="mainframe" id="mainframe" /> </frameset> </html>
i able intercept links clicked on frame "mainframe". thought add ready event live bind click events doesn't work. ideas?
note: files on same domain not xss issue.
<script> $(document).ready(function(){ $('#mainframe').ready(function() { var f = document.getelementbyid('mainframe').contentwindow.document; $('a', f).live('click', function() { alert('u click'); return false; }); }); }); </script>
you need add context jquery statement, tell #mainframe a
oh yeah....you need make sure iframe loaded. "live" should take care of that...but i'm working on had write custom ready() plugin jquery make sure frames loaded, because having trouble chrome.
chrome , ie seem jump gun on document.addeventlistener("domcontentloaded"... believe ready() functions in jquery use.
anyways, make sure iframes loaded way.
Comments
Post a Comment