更改页面刷新时的URL [英] Change the URL on page refresh

查看:91
本文介绍了更改页面刷新时的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在页面上

www.example123.com/search?error=1

www.example123.com/search?error=1

.在页面刷新时,应使用以下网址加载页面.

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

www.example123.com/search

www.example123.com/search

www.example123.com/search?error =

www.example123.com/search?error=

如何在js或jQuery中做到这一点?该解决方案应可在所有主要浏览器上使用.

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

感谢您的帮助!

推荐答案

我使用unload事件做到了.刷新页面时将调用此事件.

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);
     }
});

然后,页面将使用新的URL刷新.

Then the page will be refreshed with the new URL.

让我知道这在任何情况下都行不通.

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

注意:它不适用于Chrome.如何使其在chrome中工作?

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

这篇关于更改页面刷新时的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆