View Full Version : How to run a js file from the address bar

01-17-2009, 03:44 AM
Instead of using javascript:alert('hi'), suppose I store alert('hi') in x.js and put it on host.com/x.js. Is there a way to execute host.com/x.js directly from the address bar using javascript:? Thanks.

01-17-2009, 03:57 AM
javascript:var scr=document.createElement("script");scr.src="http://example.com/asdf.js";document.getElementsByTagName("head")[0].appendChild(scr);void(0);

after you call that, you can use your JS file.


01-17-2009, 04:12 AM
I've asked this on 5 different sites, and you are the only person who has a solution, and it worked perfectly. Thanks for saving my day!

01-17-2009, 06:16 AM
I just tried to put your trick to some work and ran into another problem

My fla has only one empty frame and my actionscript has only one line:

getURL("javascript:var js=document.createElement('script');js.type='text/javascript';js.src='hosturl/x.js';document.body.appendChild(js);void(0);", "_self");

After I compile the fla and play the swf in my browser, x.js is executed, but there is an infinite loop that causes the x.js to be executed repeatedly.

Any idea on how I can get out of this infinite loop? Thanks.