我想在某些事件时获取/设置当前页面的URL。如何获取/设置当前页面URL(跨越时空浏览器版本)
似乎有不止一种做法,如下面的问题/答案中所述。
使用jQuery
Get URL - $(location).attr('href');
Set URL - $(location).attr('href',url);
使用JavaScript
Get URL - myVar = window.location.href;
Set URL - window.location.href = "http://stackoverflow.com";
哪种方法跨越时空的浏览器版本的作品?
Get current URL in JavaScript?
How to redirect to another webpage in JavaScript/jQuery?
window.location.replace为好,因为重定向我猜。我的意思是它不像点击一个链接,而是像被重定向。 –