I am trying to write a userscript that will remove the effects of onselectstart
from an id on a page.
So far I am assuming that I can rebind the original function using something like this:
JavaScript
x
2
1
document.getElementById('nodrag').onselectstart = function() { /* code original action */ };
2
Any ideas would be appreciated.
Advertisement
Answer
Looks like I managed to work out the answer. Thank you LightStyle for giving me the hints.
So I create an script tag with document.getElementById('nodrag').onselectstart = function() { };
inside it and append this to the body.
JavaScript
1
7
1
// Create the script to remove the nodrag from chrome
2
var script = document.createElement('script');
3
script.type='text/javascript';
4
script.innerHTML = "document.getElementById('nodrag').onselectstart = function() { };";
5
var body = document.getElementsByTagName('body')[0];
6
body.appendChild(script);
7
This might not work in traditional contexts however works a charm on a userscript. Here is the final script: