Page 1 of 1

[NOT solved completely]Including js file in address bar

Posted: Sun Mar 27, 2005 2:45 pm
by yoko
Is it possible at all? Is there any way to include a javascript file by typing into the address bar? I am working on a website and my internet's really slow. So lots of time i'll just test my page cliently and then upload the new page. But i found typing "javascript: ***** void 0;" very frustrating. So is there a function or something that let's you to load a js file into the page?
Thanks in advance[/url]

Posted: Sun Mar 27, 2005 3:02 pm
by Chris Corbyn
???? :?

Not sure what you mean but I think if you are talking about loading an external JS file then you just mean....

Code: Select all

<script language=&quote;javascript&quote; type=&quote;text/javascript&quote; src=&quote;yourfile.js&quote;></script>

Posted: Sun Mar 27, 2005 3:07 pm
by yoko
Yes that's the code to use to include js file within a web page; what if i want to include an js file dramanicly. by typing something into the address bar

Do i have to use DOM to create "<script language="javascript" type="text/javascript" src="yourfile.js"></script>" or is there an easier way?

Posted: Sun Mar 27, 2005 3:15 pm
by Chris Corbyn
Use PHP. Yeah I guess you could technically do some DOM scripting and evaulate what to dynamically create based upon the location object but PHP is far simpler ....

Code: Select all

<html>
<head>
<title>Dynamic JS Loader</title>
<?php
$js = $_GET['js'];
if (!empty($js)) {
    echo '<script language="javascript" type="text/javascript" src="'.$js.'"></script>';
}
?>
</head>
<body>
....
So "yourfile.php?js=functions.js" would output:

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Dynamic JS Loader&lt;/title&gt;
&lt;script language=&quote;javascript&quote; type=&quote;text/javascript&quote; src=&quote;functions.js&quote;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
....

Posted: Sun Mar 27, 2005 3:20 pm
by yoko
that's great!

So then another idea came to my mind. Is there anyway to disable the "same-origin policy" on my own computer? I believe i should be in control of my own IE.

Posted: Sun Mar 27, 2005 5:53 pm
by yoko
Or better yet, can i fool IE so that IE thinks it's Host A Port B while it is HOst C Port D?