0

The following code works for the first time that the page is loaded but when the page is refreshed using F5, it does not work on Firefox. In Chrome it works fine.

$(document).ready(function() {
    $("iframe").each(function() {
        // Using closures to capture each one
        var iframe = $(this);
        iframe.on("load", function() { // Make sure it is fully loaded
            iframe.contents().click(function(event) {
                iframe.trigger("click");
            });
        });

        iframe.click(function() {
            alert("Clicked...");
        });
    });
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Smila
  • 1,130
  • 8
  • 16

2 Answers2

0

This code works fine for me

$(document).ready(function () {
    document.getElementById('main_iframe').contentWindow.location.reload(true);
    $('iframe').load(function () {
        $(this).contents().find("body").on('click', function (event) {
            alert("clicked....")
        });
    });
});
Shaunak D
  • 20,588
  • 10
  • 46
  • 79
Smila
  • 1,130
  • 8
  • 16
-2

put all your code in jQuery(function(){ //here }) and all will be ok. That runs whens the page loads, each f5 action, remove the other code for testing reload.

Patrick Mutwiri
  • 1,301
  • 1
  • 12
  • 23