I have a JavaScript bookmarklet that is working fine in Chrome (v21) and Safari (v6) but when I try to use it in Firefox (v14) or IE (v9) and I get a page that just says:
[object HTMLScriptElement]
The bookmarklet is this (all the PHP statement at the end inserts the API key):
javascript: (function(src, cb) {
var s = document.createElement('script');
s.charset = 'UTF-8';
document.body.insertBefore(s, document.body.firstChild);
s.src = src;
if (typeof cb === 'function') {
s.onload = cb;
s.onreadystatechange = function() {
(/loaded|complete/).test(s.readyState) && cb(s);
};
}
return s;
}('http://towatchlist.com/marks/bookmarklet2response?uid=<?php echo $userID; ?>'))
I don't think it's even loading the bookmarklet at all. In Firefox the URL bar changes to be the code above; in IE it doesn't even change from whatever page it's on.
I did try wrapping the bookmarklet in a self-executing function expression as suggested elsewhere, but that just resulted in
Uncaught SyntaxError: Unexpected token (
in the Chrome console (and nothing else). Here's how I wrapped it:
javascript: (function() {
function(src, cb) {
var s = document.createElement('script');
s.charset = 'UTF-8';
document.body.insertBefore(s, document.body.firstChild);
s.src = src;
if (typeof cb === 'function') {
s.onload = cb;
s.onreadystatechange = function() {
(/loaded|complete/).test(s.readyState) && cb(s);
};
}
return s;
}('http://towatchlist.com/marks/bookmarklet2response?uid=<?php echo $userID; ?>')
}());
Perhaps I didn't wrap it quite right? In any case, what do I need to change in order to make IE/Firefox actually execute the bookmark?