Making script wait until iframe has loaded before running

后端 未结 3 1722
一个人的身影
一个人的身影 2020-12-16 11:27

The site I\'m working on has a Live Chat plugin on an iframe. I\'m trying to change an image if there are no agents available. My code works on the console, but nothing on t

3条回答
  •  眼角桃花
    2020-12-16 12:14

    Another way to bind to the load event of an iframe is to attach a load listener to the iframe before adding a src tag to the iframe.

    Here's a simple example. This will also work with iframes that you don't control.

    http://jsfiddle.net/V42ts/

    // First add the listener.
    $("#frame").load(function(){
        alert("loaded!");
    });
    
    // Then add the src
    $("#frame").attr({
        src:"https://apple.com"
    })
    

提交回复
热议问题