1

I am having problems in redirecting page with jquery. I have a variable url which contains localhost/abc#123. When i write document.location.href = url;, the page redirects to localhost/abc leaving #123. How to resolve this issue

4

1 回答 1

3
var url = "http://bing.com/refresh/test.html#123";

document.location.href=url

它在我的 Firefox 中对我来说很好。您是否尝试过调试您身边发生的事情。我已经在 IE8 + firefox + chrome 中测试了这段代码。我希望它对你有用。

如果此代码对您不起作用,请尝试

window.location.replace(url)

作为您的评论,您似乎使用过 Anchor,所以尝试了这个。

$("#myanchor").click(function(e){
e.preventDefault();

// redirect code here
});
于 2012-10-05T04:57:02.170 回答