如何在每次使用f5刷新页面时运行Javascript函数
以下代码在页面首次加载时起作用,但当使用F5刷新页面时,它在firefox上不起作用。在铬合金中工作良好如何在每次使用f5刷新页面时运行Javascript函数,javascript,jquery,javascript-events,onload-event,Javascript,Jquery,Javascript Events,Onload Event,以下代码在页面首次加载时起作用,但当使用F5刷新页面时,它在firefox上不起作用。在铬合金中工作良好 $(document).ready(function() { $("iframe").each(function() { // Using closures to capture each one var iframe = $(this); iframe.on("load", function() { // Make sure it i
$(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...");
});
});
});
将所有代码放入
jQuery(function()中){
//这里
})
一切正常。当页面加载时运行,每个f5操作都会删除其他代码以进行重新加载测试 这段代码对我来说很好用
$(document).ready(function () {
document.getElementById('main_iframe').contentWindow.location.reload(true);
$('iframe').load(function () {
$(this).contents().find("body").on('click', function (event) {
alert("clicked....")
});
});
});
在什么浏览器中尝试“ctrl+f5”时是否相同?抛出了哪些错误?请检查此处使用
.on()
附加事件处理程序,如iframe.on(“单击”,“a.offsite”,function(){alert(“单击…”);})代码>请参阅参考: