开发者

Add an onclick attribute to a link tag using Greasemonkey

开发者 https://www.devze.com 2023-03-25 05:27 出处:网络
I have an internal website that has a link with NO onClick attribute present. I want to add an onclick attribute with a function as the value, like so:

I have an internal website that has a link with NO onClick attribute present.

I want to add an onclick attribute with a function as the value, like so:

onClick="LinkTracker();return true"

So that I get a call to the function, but the link click is still fol开发者_运维百科lowed by the browser.

I tried:

item.onclick=Function("LinkTracker();return true");

I also tried just a simple function with no return info, and that function was never called either.

When I inspect the link element with Firebug, I do not see the onclick attribute set.

I DO see the href value (which I changed) properly updated.

Any clues?


item.onclick=function(){LinkTracker();return true;}

try that.

test case

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号