Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to run a js file from the address bar

    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.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Code:
    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.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!

  • #4
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •