[英]How to run a javascript function when a page dynamically loads content
I am currently writing some Javascript code that adds some tags across text in an HTML file after the page loads. 我目前正在编写一些Javascript代码,以在页面加载后跨HTML文件中的文本添加一些标签。 I use the
我用
window.onload
method for achieving this. 实现此目的的方法。
However, I am facing an issue in pages like google plus, where you get more content as you scroll down. 但是,我在google plus之类的页面中遇到问题,向下滚动时您会获得更多内容。 Is there a way of calling my JS function when such a page adds more content?
当此类页面添加更多内容时,是否可以调用我的JS函数?
Thanks 谢谢
Akshay 阿克沙伊
There are several ways how to get this working. 有几种方法可以使它起作用。 You can either use jquery like this:
您可以像这样使用jquery:
$('#mydiv').bind("DOMSubtreeModified",function(){
// your code goes here
alert('changed');
});
Note that this is not supported in IE8( and below). 请注意,IE8(及以下)不支持此功能。
Or you can run loop and continuously fire the desired code: 或者,您可以运行循环并连续触发所需的代码:
var interval = setInterval(function() {
// your code goes here
}, 1000);
Fiddle: http://jsfiddle.net/8RF5r/5/ 小提琴: http : //jsfiddle.net/8RF5r/5/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.