如何在localhost上设置window.location,包括IE 8下的哈希标记

Lyn*_*ley 5 javascript internet-explorer

我有一个用于更改当前URL的书签.代码是:

javascript:location.href ='http:// localhost:8888/#nominate'

但是,在IE8下,这最终会将浏览器发送到:http:// localhost:8888 /

如何将IE8发送到该hashmark位置?

谢谢.

jfr*_*d00 4

有两件事要尝试:

window.location = 'http://localhost:8888/#nominate';
window.location.assign('http://localhost:8888/#nominate');
Run Code Online (Sandbox Code Playgroud)

该规范还允许您直接设置 window.location.hash 值,但您不必这样做。