如何在每次使用 f5 刷新页面时 运行 一个 Javascript 函数
How to run a Javascript function everytime f5 is used to refresh the page
以下代码在第一次加载页面时有效,但当使用 F5 刷新页面时,它在 Firefox 上不起作用。在 Chrome 它工作正常。
$(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(){
//here
})
,一切都会好的。在页面加载时运行,每个 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....")
});
});
});
以下代码在第一次加载页面时有效,但当使用 F5 刷新页面时,它在 Firefox 上不起作用。在 Chrome 它工作正常。
$(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(){
//here
})
,一切都会好的。在页面加载时运行,每个 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....")
});
});
});