1

I'm trying to write a Google Chrome extension that removes the onmousedown event from a <a> tag on a website.

Earlier that site used to have onmousedown event as part of the DOM so I could easily remove it via content script by calling element.removeAttribute("onmousedown"). But now, they add that event via javascript so it's not possible for me directly remove that event via content script as it runs in a different javascript context.

PS: I'm specifically talking about onmousedown event on links on google search results page. Earlier, this small piece of code used to work but now it doesn't as onmousedown is not part of the DOM now.

var all_main_links = document.getElementsByClassName("r");
for (i=0; i<all_main_links.length; i++){
    var current_link = all_main_links[i].childNodes[0];
    current_link.removeAttribute("onmousedown");
    }
shadyabhi
  • 16,675
  • 26
  • 80
  • 131
  • Take a look at [injecting your code into the page's context](http://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script). It may be the only way. – Xan Jul 15 '14 at 07:37
  • I've been puzzling over [this question](http://stackoverflow.com/q/24718605/2336725), and @Xan may have figured out what was going on. – Teepeemm Jul 15 '14 at 13:54
  • @Xan That link definitely helped and solved my issues. Thanks :) – shadyabhi Jul 16 '14 at 06:22

1 Answers1

0

A content script cannot access in page javascript object (such as onmousedown event declared by javascript). They're executed in a sandbox.

But what you can do is inserting a script in the head of the page (with script tag) wich shutdown the event :)