Javascript重定向window.location.url和.hash

Javascript重定向window.location.url和.hash,javascript,Javascript,我正在尝试重定向和传递参数 // I'm at: http://example.com/index.html var url = 'http://example.com/category.html'; var hash = '#testsite'; // Ignores # and all after window.location.href = url + hash; // Does not work, sets hash first, then redirects to url with

我正在尝试重定向和传递参数

// I'm at: http://example.com/index.html
var url = 'http://example.com/category.html';
var hash = '#testsite';

// Ignores # and all after
window.location.href = url + hash;

// Does not work, sets hash first, then redirects to url without maintaining hash
window.location.href = url;
window.location.hash = hash;

使用javasript可以像这样重定向吗?

也许您可以尝试下面的方法

var url = 'http://example.com/category.html';
var hash = '#testsite';
window.open(url+"?hash="+hash,"_self");
//http://example.com/category.html?hash=#testsite

不确定什么是
模板定位
,但这很有效:

var url='1〕http://example.com/category.html';
var hash='#testsite';

window.location.href=url+hash刚刚注意到,这是一个在加载后立即删除我的#和之后的站点。我得调查一下是什么把它拿走的。。。最后一个小时我一直在胡思乱想为什么它不起作用。我的意思是,重定向是正确的。。。但另一个脚本在页面加载后立即将其从url中删除。所以我没有看到它,并假设它没有被传递。如果我没有错的话,它将通过#testsite作为查询参数。对吗?我不想不幸的。。谢谢你的努力!