/    Sign up×
Community /Pin to ProfileBookmark

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 it possible to execute host.com/x.js directly from the address bar using javascript:? Thanks.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorJan 17.2009 — [CODE]
javascript:var js=document.createElement('script');js.type='text/javascript';js.src='__URL_HERE__';document.body.appendChild(js);void(0);
[/CODE]
Copy linkTweet thisAlerts:
@A1ien51Jan 17.2009 — How many places did you ask this?
Copy linkTweet thisAlerts:
@whininguserauthorJan 17.2009 — @voidvector

It worked perfectly. Thanks a lot!

@A1ien51

about 5, but only you and voidvector got it. Thanks to you and voidvector's help, now I can go to bed.
Copy linkTweet thisAlerts:
@whininguserauthorJan 17.2009 — About 5, and many thanks to you both!

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.
Copy linkTweet thisAlerts:
@voidvectorJan 17.2009 — I don't think the loop is caused by JavaScript. I don't know ActionScript.

When I use it in regular JavaScript, it only runs once.
Copy linkTweet thisAlerts:
@JunkMaleJan 17.2009 — Use AJAX instead of of Actionscript to do your fetching. Then eval to responseText to get JavaScript to run the script.
Copy linkTweet thisAlerts:
@toicontienJan 17.2009 — AJAX will only work if the web page is hosted on the same domain as the JavaScript. If your FLA only has one frame and it's executing x.js repeatedly, is your FLA simply repeating that first frame?
Copy linkTweet thisAlerts:
@whininguserauthorJan 18.2009 — Problem solved. All of your help are pretty relevant and much appreciated.
×

Success!

Help @whininguser spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...