Adding event handlers via onClick etc does not work in Greasemonkey scripts.
See #2 in this post from 2005 ;) http://www.oreillynet.com/pub/a/network/2005/11/01/avoid-common-greasemonkey-pitfalls.html?page=3 Regards, kwah On 10 April 2011 22:02, stAAsek <[email protected]> wrote: > I'm trying to add a script that will display confirm dialog asking > "Leave the page?" when user clicks on any link. > I'm using FF 4.0 and Greasemonkey 0.9.1. > > Script below doesn't work > // ==UserScript== > // @name Test > // @namespace abc > // @description None > // @include * > // ==/UserScript== > var m = "Leave the page?"; > var an = document.getElementsByTagName("a"); > > for (a = 0; a < an.length; a++) { > an[a].onclick = function () { return confirm(m); } > > } > > > Following doesn't work either: > > window.onload = load; > function load() > { > var m = "Leave the page?"; > var an = document.getElementsByTagName("a"); > > for (a = 0; a < an.length; a++) { > an[a].onclick = function () { return confirm(m); } > > } > } > > but it works as a custom javascript (without greasemonkey) > Can somebody please help me with the code? > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "greasemonkey-users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/greasemonkey-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.
