附加到网址并刷新页面 [英] append to url and refresh page

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

问题描述

我希望编写一段javascript,将参数附加到当前网址然后刷新页面 - 我该怎么做?

I am looking to write a piece of javascript that will append a parameter to the current url and then refresh the page - how can I do this?

推荐答案

这应该有效(未经过测试!)

this should work (not tested!)

var url = window.location.href;    
if (url.indexOf('?') > -1){
   url += '&param=1'
}else{
   url += '?param=1'
}
window.location.href = url;

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

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