Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I m currently on a page

www.example123.com/search?error=1

. On page refresh, the page should be loaded with the following url.

www.example123.com/search

or

www.example123.com/search?error=

How to do this in js or jQuery? The solution should work in all major browsers.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

I did it using unload event. This event will be called when a page is refreshed.

$(window).unload(function() {
     var currentURL = window.location.href;
     var index = currentURL.indexOf("?error=");
     if(index > -1) {
         window.location.href = currentURL.substring(0, index);
     }
});

Then the page will be refreshed with the new URL.

Let me know if this will not work in any case.

Note: It doesnt work in chrome. How to make it work in chrome?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...