2013-12-19 54 views
3

我想有一个简单的书签,其在任何URL小书签在每个URL

我用的末尾增加了一个简短的参数?clearcache清空内部缓存的末尾添加参数,所以为了不每次键入它,我正在寻找一个简单的解决方案

我的网站是

http://subdomain.mysite.net/ 

,并与书签我想使URL去

http://subdomain.mysite.net/?clearcache 

同样的,更深层次的网页,我想它去

http://subdomain.mysite.net/some-page/?clearcache 

我目前正在

javascript:location=location.href.replace(/http:/g,"/?clearcache") 

努力,但它不工作

当我点击那书签,我的网址变成

http://subdomain.mysite.net/?clearcache//subdomain.mysite.net/ 

我觉得我是cl呃,但我只需要专家的一点小建议。 我希望有个答复。 感谢

回答

5

这应该解决您的问题:

代码

javascript:void((function(){var loc = location.href; loc.indexOf("?") == -1 ? (location.href = loc+"?clearcache") : (location.href = loc+"&clearcache");})());

说明

是否有其他的查询字符串参数存在。如果是,则在末尾附加clearcache,使用&或附加到URL使用?

+1

谢谢。 我使用了一个更简单的版本,这似乎对我的案件起作用。它只是在我的鼻子前面,我错过了它 'javascript:location = location.href.replace(location.href,“?clearcache”)' 我检查了HTTP标头并且URL有?clearcache at结束。我希望它可以帮助其他人 – valdroni

+1

在添加参数之前,最好检查它是否已经存在于URL中。这个修改版本可以这样做:'javascript:void((function(){var loc = location.href; if(loc.indexOf('clearcache')> = 0)return; loc.indexOf(“?”)<0 ?(location.href = loc +“?clearcache”):(location.href = loc +“&clearcache”);})());' –

+0

谢谢大家。我拿了@valdroni最简单的版本 – elbaulp