I guess you should be able to do the following:
javascript:(function () {
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://depot.com/file.js';
document.getElementsByTagName('body')[0].appendChild(newScript);
})();
Here's a very useful example (paste this in your address bar):
javascript:(function () {
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://cornify.com/js/cornify.js';
document.getElementsByTagName('body')[0].appendChild(newScript);
for (var i = 0; i < 5; i++) {
newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://cornify.com/js/cornify_run.js';
document.getElementsByTagName('body')[0].appendChild(newScript);
}
})();
Voila:
In fact, this is how cornify.com is including the remote scripts in their bookmarklet.
UPDATE:
As @Ben noted in the other answer, it's not that straightforward to call a function defined in your remote script. Ben suggests one solution to this problem, but there is also another solution, the one that cornify are using. If you check out http://cornify.com/js/cornify_run.js
you'll see that there's just one function call in that file. You could place your funcname()
call in a separate JavaScript file, as cornify are doing, because script blocks are guaranteed to be executed in the order they are inserted. Then you'd have to include both scripts, as in the following example:
javascript:(function () {
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://depot.com/file.js';
document.getElementsByTagName('body')[0].appendChild(newScript);
newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://depot.com/file_run.js';
document.getElementsByTagName('body')[0].appendChild(newScript);
})();
Where the file_run.js
simply includes a call to funcname()
.