【发布时间】:2012-10-23 07:36:51
【问题描述】:
我想知道在网站加载时是否有任何可能的方法来重写 URL 以包含井号标签?
示例:
www.google.com 会自动变为 www.google.com#something?
谢谢。
【问题讨论】:
标签: javascript html css web
我想知道在网站加载时是否有任何可能的方法来重写 URL 以包含井号标签?
示例:
www.google.com 会自动变为 www.google.com#something?
谢谢。
【问题讨论】:
标签: javascript html css web
是的,你可以这样做。
location.hash = 'something';
运行这段代码会将“#something”添加到该页面的 URL。
【讨论】:
<script> 标记内。
如果你想自动从www.google.com重定向到www.google.com#something
您可以使用 firefox 的重定向器插件。
每当您加载 www.google.com 时,插件都会自动将地址栏中的 URL 更改为 www.google.com#something(或您指定的任何内容。)
或者,您可以使用名为greasemonkey 的firefox 插件来编写Jacob 给出的1 行脚本。这也将达到目的。
当然,这两种解决方案都是 firefox 特有的。
【讨论】:
这是一个简单的方法,如果我误解了你的问题,请纠正我! 首先使用 location.hash 将“#something”添加到您的 URL 然后使用 javascript 中的 window.location 重定向到该位置。 试试这个 sn-p:
<html>
<head>
<script type="text/javascript">
location.hash = "something";
window.location = location.hash;
</script>
</head>
</html>
【讨论】: