0

I'm trying to wrap my head around building a simple Chrome extension that replaces a certain tag's property on a webpage.

The site has the following code:

<body ondragstart="return false;" onselectstart="return false;">

thus making text on the web page unselectable. I'm trying to make the text selectable.

I tried this code in my script.js:

$(document).ready(function () {         
    $('body').live('selectstart dragstart', function (evt) {
        evt.allowDefault();
        return true;
    });
});

and:

$(document).ready(function(){               
    var bd = document.getElementById('body');
    bd.addEventListener('selectstart', start, true);
    bd.addEventListener('dragstart', start, true);
});

My manifest is as follows:

{
   "browser_action": {
      "default_icon": "chav.jpg"
   },
   "content_scripts": [ {
      "js": [ "jquery.js", "content_script.js" ],
      "matches": [ "http://www.chavaramatrimony.com/*" ]
   } ],
   "description": "Lets you select text",
   "icons": {
      "128": "chav.jpg"
   },

   "manifest_version": 2,
   "name": "ChavaraMatrimony Unlocker",
   "update_url": "https://clients2.google.com/service/update2/crx",
   "version": "1.1"
}

None of them seem to work. The console shows an error: "Uncaught TypeError: undefined is not a function".

I would be glad for some help on what I'm doing wrong going about this.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Joel G Mathew
  • 7,561
  • 15
  • 54
  • 86
  • Probably not including jQuery as a content script before your own code? You should include your manifest.json in your question. – rsanchez May 19 '14 at 15:24

1 Answers1

1

I think the root of your problem is that your code is running in isolated context, that cannot access nor override page context's handlers.

See this answer for injecting your code into the page's context.

Also note, that you probably should not be looking to add another listener, but to clear existing ones.

Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206