【问题标题】:just add url on only address bar of browser [duplicate]只需在浏览器的地址栏上添加 url [重复]
【发布时间】:2012-06-01 02:51:09
【问题描述】:

可能重复:
Change the URL in the browser without loading the new page using JavaScript

我只想在浏览器地址栏中添加网址Note: dont want redirect

e.i 我有一个网址www.example.com/index.html

我想在“地址栏”上设置网址,例如www.example.com/index/page2.html

我使用document.location.hash = 'foo';

but it is add only # data like www.example.com/index.html#foo

note : i dont want to redirect only want to add url in address bar so don't answer document.location like that

有什么解决办法吗?

【问题讨论】:

  • 你不能这样做,这是出于安全原因。
  • 请查看此处发布的链接。两者都描述了如何做到这一点。安全问题限制您将其设置为另一个 url,但您可以使用历史 API 更改路径。
  • @chucktator 他能做的最好的事情就是来自他的例子是www.example.com/index.html/page2.html
  • 有可能看到这个博客并点击任何帖子标题然后它是在浏览器地址栏中的变化看到这个freesubmiturlindia.blogspot.in

标签: java javascript jquery


【解决方案1】:

在这里阅读。

http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate

可能会有帮助。

window.history.pushState('abc', "Title", "/new-url");

【讨论】:

  • NOTE : window.history.pushState('abc', "Title", "/new-url"); 不适用于 IE
【解决方案2】:

我不确定你是否可以在不使用重定向的情况下做到这一点。

不过,这是实现目标的一种方法。

www.example.com/index/page2.html 创建包含www.example.com/index.html 框架的页面

www.example.com/index.html 中,如果www.example.com/index.html 不在框架内,则将用户重定向到www.example.com/index/page2.html

【讨论】:

    【解决方案3】:

    做不到。这是一项安全功能,可让网站更难欺骗(例如用于网络钓鱼攻击)

    【讨论】:

    • 无法更改域。其余的网址都可以。因此没有欺骗的可能性。
    • 完全正确,我的错误。
    猜你喜欢
    • 2012-03-18
    • 2012-06-12
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多