从chrome扩展中监视history.push状态 [英] monitoring history.pushstate from a chrome extension

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

问题描述

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

不幸的是,似乎Chrome的孤立世界阻止了这种重写。除了轮询 document.location.href )外,是否还有其他捕获历史更改的方法?

解决方案

是,



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

  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);


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.

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)?

解决方案

Yes,

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.push状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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