This is my current bookmarklet:
javascript:(function(){ alert(location.href); })();
which seems to work fine, but for me, it doesn't work on youtube under chrome for some reason.. is there a more robust way to get the location.href? Thanks.
This is my current bookmarklet:
javascript:(function(){ alert(location.href); })();
which seems to work fine, but for me, it doesn't work on youtube under chrome for some reason.. is there a more robust way to get the location.href? Thanks.
No. You may try
(function(window){window.alert(window.location.href)})(this);
which will make sure you're not using some custom alert
function from the global namespace. But, there is no way prevent window.alert
from being overwritten like so window.alert = function () { console.log('Haha!'); };
.
The location
object should be fail-proof, since the browser's internal setter method inhibits any shenanigans there (meaning that window
's location
attribute is effectively write-protected, as is window.location
's href
attribute)
Edit:
Looks like bookmarklets don't work in Firefox 6+ due to "social engineering bookmarklet attacks", and there's nothing you can do about it.
https://stackoverflow.com/a/6643466/27862
https://bugzilla.mozilla.org/show_bug.cgi?id=527530