Another option of course, is to trigger the listen() function when you click the button. Whichever you prefer, but the way I just mentioned means that the function only runs when you click the button.
Code:<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript"> function listen() { var iframe = document.getElementById("iframe_a"); var onload = iframe.onload; if (typeof iframe.onload != 'function') { iframe.onload = alert_change; } else { window.onload = function() { onload(); alert_change(); } } }; function alert_change() { alert("thanks for visiting!"); } </script> </head> <body> <iframe name="iframe_a" id="iframe_a"></iframe> <a href="http://www.example.com/" target="iframe_a" onclick="listen()">Go!</a> </body> </html>
Bookmarks