如何使用pushstate HTML5操作浏览器历史记录 [英] How to manipulating browser histori using pushstate HTML5

查看:142
本文介绍了如何使用pushstate HTML5操作浏览器历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Html5附带推送弹出功能..使用此命令更容易操作浏览器..



Html5 coming with Pushing n Popping feature .. and more easy to manipulating browser using this command ..

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");





来自这个Mozilla的例子。 org

但是我试图用另一个网址来替换bar.html,比如http://youtube.com ..它卡住了,我不能去目的地..

怎么做...请帮帮我..谢谢



我尝试过的事情:





example from this Mozilla.org
but i trying to replace bar.html using another url website like http://youtube.com .. it stuck and i can't goes to destination ..
how to do that .. please help me .. thanks

What I have tried:

<pre>var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");

推荐答案

你不能出于安全原因这样做



操纵浏览器历史记录 - Web API | MDN [ ^ ]



You can't do this for security reasons

Manipulating the browser history - Web APIs | MDN[^]

引用:

新网址必须与当前网址的来源相同

The new URL must be of the same origin as the current URL





请不要问它是怎么做的,或者是否有另一种方式这样做,为什么浏览器不会让你假装成另一个网站应该是相当明显的。



Please don't ask how it can be done anyway, or is there another way of doing this, it should be fairly obvious why the browser won't let you pretend to be another site.


引用:

如何使用pushstate HTML5操作浏览器历史记录

How to manipulating browser histori using pushstate HTML5



简答:你没有。

Webapps不允许在客户端改变东西侧。否则,恶意软件滥用此功能需要多长时间?


Short answer: you don't.
Webapps are not allowed to change things on client side. Otherwise, how long would it take to malware to abuse the feature ?


这篇关于如何使用pushstate HTML5操作浏览器历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆