从 chrome 扩展监控 history.pushstate [英] monitoring history.pushstate from a chrome extension

查看:27
本文介绍了从 chrome 扩展监控 history.pushstate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Chrome 扩展来调整 Facebook.但是,在支持 HTML5 的网站(如 Facebook)中捕获浏览操作需要覆盖 window.history.pushState,如在这个 SO 问题中.

I am developing a Chrome extension to tweak Facebook. However, catching browsing actions within HTML5-enabled sites such as Facebook requires an override of window.history.pushState as explained in this SO question.

不幸的是,Chrome 的孤立世界似乎阻止了这种覆盖.有没有其他方法可以捕获历史更改(除了轮询 document.location.href)?

Unfortunately, it seems that Chrome's isolated worlds prevent this sort of override. Is there any other method of catching history changes (other than polling document.location.href)?

推荐答案

是,

一种方法是创建一个脚本标记并将您的代码放在那里:

One way is to create a script tag and put your code there:

html = "window.history.pushState = function(a,b,c) { alert('Change !'); };";

var headID = document.getElementsByTagName("head")[0];         
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.innerHTML = html;
headID.appendChild(newScript);

这篇关于从 chrome 扩展监控 history.pushstate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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