English 中文(简体)
如何用jquery或javascript重载或更新网页?
原标题:How to check page is reloading or refreshing using jquery or javascript?

I have to do some kind of operation on the page refresh or reload. that is when I hit next page or Filter or refresh on the grid. I need to show some confirmation box over this Events.

是否有任何事件可以告诉你哪一页是作案手? 复读或读? 使用javascript?

成就

问题回答

如果是复读(或者用户正在离开网站/张贴浏览器),window.onunload将火灾。

// From MDN
window.onunload = unloadPage;
function unloadPage()
{
    alert("unload event detected!");
}

https://developer.mozilla.org/en/DOM/window.onunload

如果你只想一个确认箱,允许他们停留,则使用:

window.onbeforeunload = function() {
    return "Are you sure you want to navigate away?";
}

你们可以建立一个隐蔽的领域,将其价值放在第一页的负荷上。 当该网页再次装上时,你可以检查隐藏的现场。 如果该网页空洞,则该网页第一次装满,否则就会重新启用。 比如:

<body onLoad="CheckPageLoad();">

    <input type="hidden" name="visit" id="visit" value="" />

</body>

JS

function CheckPageLoad() {
    if (document.getElementById("visit").value == "") {
        // This is a fresh page load
        document.getElementById("visit").value = "1";
    }
    else {
        // This is a page refresh
    }
}​

我认为这是关键的。

First, the refresh/hidden field system works on the beginning of the new page copy and after, not on leaving the first page copy.

从我对这种方法和其他一些方法的研究来看,主要由于隐私标准,在卸载或更早时无法发现一页的复读。 只是在新网页装满后。

我也提出了类似的问题要求,但基本上是在停机坪上结束会议,在考虑这一问题的同时,发现浏览器将重载/重装作为两个不同的部分:

  1. close the current window (fires onbeforeunload and onunload js events).
  2. request the page as if you never had it. Session on server of course has no issue, but no querystring changes/added values to the page s last used url.

这些情况也是在这个秩序中发生的。 只有一种习俗或非标准浏览器才能不同行事。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签