Chris R.
Chris R.

Reputation: 699

Javascript replace isn't working?

I'm working on a greasemonkey script, but the str.replace function isn't working.

I'm trying to disable the onmousedown functions for Google searches, my thought was that by replacing that with nothing, it would just get rid of it.

Here's the code they're using.

<a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=5&amp;ved=0CFIQFjAE&amp;url=http%3A%2F%2Fswengineeringnotebook.blogspot.com%2F2010%2F01%2Fjquery-disable-default-event.html&amp;ei=O0nJTqeKOeaosQKMyoBk&amp;usg=AFQjCNHcR98HxCj8kdeVLlBiADbelsvEgw" class="l" onmousedown="return rwt(this,'','','','5','AFQjCNHcR98HxCj8kdeVLlBiADbelsvEgw','','0CFIQFjAE')">My Software Engineering Notebook: <em>JQuery Disable Default</em> Event</a>

As you can see, they've got the onmousedown in their links.

Here's what I'm using to get rid of it.

$('body').text().replace(/onmousedown=\"return rwt\(.*?\)\"/gi, "");

I've also tried redefining the rwt function with just "return false;" but that also seems to have no effect.

Any ideas on how to make this would would be much appreciated.

Thanks.

Upvotes: 0

Views: 216

Answers (1)

gustavotkg
gustavotkg

Reputation: 4399

I am not sure if I got your question, but as you tagged with jQuery and You want to remove onmousedown attribute, I'd do:

$("a").removeAttr('onmousedown');

If it does not work, maybe You could try unbinding:

$("a").unbind('mousedown');

Upvotes: 2

Related Questions