开发者

window.location = window.location not work in IE7

To refresh the page I am using window.location = window.location it wor开发者_如何学编程ks fine with FireFox but not with IE7

any Idea??

Thanx


Call the reload method instead

location.reload(true)


To reload the page, the good solution is to use window.location.reload();

You say this pops up for confirmation? This is probably because the page you are on was called with POST data sent.

If you want thoses POST data to be sent again, you don't have an easy solution to avoid this confirmation (maybe using ajax you could do it.... you'll spend a lot of time doing this).

If you don't want to POST again the data, than you don't want to reload the page ! You only want to load the same URL.

The problem is, if you say to your browser, load this URL, it will do nothing because the URL you're speaking of is already loaded (for most browser, no URL change -> no page reload) !!

An easy way to get around this problem can be to call the same URL plus a random query string value. This way the URL you call is a new one.

To do this a really easy way :

window.location.search += '&' + Math.random();

One problem with this solution is that your URL can become messy....

Depending on your needs and your URLs, you can probably find a way to make very little changes, just enough to make the browser reload the page.


Another simple solution is submitting empty form.. tested it now for IE, FF and Chrome:

function Reload() {
    var oForm = document.createElement("form");
    document.body.appendChild(oForm);
    oForm.submit();
}

This way you can also read the posted data back from the server and submit it again without having the "confirmation" you mentioned, if it's relevant let us know what server side language you're using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜