我试图通过使用YouTube来检测history.pushState上的页面更改,但它似乎从未触发过。我最终想要让这个脚本从Tamper猴子/Greasemonkey脚本中运行,为此,我理解您需要将脚本插入到实际页面中,我已经这样做了,但没有结果:
html =
"var oldState = history.pushState;"+
"history.pushState = function() {" +
"alert('url changed');" +
"return oldState.apply(this);" +
"}";
var head = document.getElementsByTagName("body")[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = html;
head.appendChild(script);我还尝试从调试控制台运行相同的代码:
var oldState = history.pushState;
history.pushState = function() {
alert('url changed');
return oldState.apply(this);
};但这似乎也做不到。有人知道这是怎么回事吗?
https://stackoverflow.com/questions/30199242
复制相似问题