我正在尝试编写一个用户脚本,该脚本将从页面上的 id 中删除 onselectstart
的影响。
到目前为止,我假设我可以使用如下方式重新绑定(bind)原始函数:
document.getElementById('nodrag').onselectstart = function() { /* code original action */ };
任何想法将不胜感激。
最佳答案
看来我已经找到答案了。感谢 LightStyle 给我的提示。
因此,我创建了一个脚本标记,其中包含 document.getElementById('nodrag').onselectstart = function() { };
并将其附加到正文中。
// Create the script to remove the nodrag from chrome
var script = document.createElement('script');
script.type='text/javascript';
script.innerHTML = "document.getElementById('nodrag').onselectstart = function() { };";
var body = document.getElementsByTagName('body')[0];
body.appendChild(script);
这在传统环境中可能不起作用,但在用户脚本上却很有用。这是最终的脚本:
关于javascript - 解除绑定(bind).onselectstart 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17469574/