November 28, 2001
Foreign scripts with bookmarklets
This cool bookmarklet from Josh Santangelo exposes all of the <!-- comments --> in the web page you happen to be looking at, and introduces an intriguing thing: the bookmarklet imports a JavaScript file from another domain and attaches it to the page, via the DOM interface. Look at this code snippet (from the bookmarklet):
scScript=document.createElement(’script’);
scScript.src=’http://dbz.nu/x/showcomments.js’;
scScript.type=’text/javascript’;
scScript.defer=true;
void(document.getElementsByTagName(’head’)[0].appendChild(scScript));
The script then runs in the context of the page being viewed, even though it’s a foreign script from another domain. Hmmm. (linkage via Matt)










