Question: I want to write a bookmarklet that will modify any webpage so that when the JavaScript code on that page does something like `document.location = 'http://site.tld'` or `document.location.href = 'http://site.tld'` the page will open a new tab or window instead of changing location; same as if code was `window.open('http://site.tld')`;

Can I modify the prototype somehow to achieve this goal? (I use this word carelessly because although I've read about modifying prototypes a few times, I've never actually done it.) Or is there some other way?

Answer: 
I tried different methods but it's almost impossible to trace the href of the target window.

Using 

```
window.onbeforeunload = function(e) {
    window.open(document.location.href);
};

```

will open your current window in another tab and the target in current window. The problem is that onbeforeunload is triggered not only on changing the location of the window, even on closing window or refreshing it. Depends where you want to use it.

PS:

```
window.onunload = function() {
    document.location = document.location;
}

```

if you test this, when you change the page location, you will be able to see the new url in the address bar for a moment then you will be redirected to your current page. I didn't managed to get the new target. Good luck!
You could only do something with the prototype if it were a function call rather than an assignment. For example in the case of document.write 

```
document.write = function(txt) {
   alert("txt");
};

document.write("test");   

```