Link to home
Create AccountLog in
Avatar of wael_shehab
wael_shehabFlag for Saudi Arabia

asked on

Referencing JavaScript file by physical path

I want to load a local javascript file in an HTML page by referencing its full physical path.
It worked properly when testing it on my local machine, but after uploading to an IIS 7.5 server the following error raised:
Not allowed to load local resource: file///E:/testJS/localscript.js

Below is a sample of the HTML page and the JavaScript file:

HTML Page
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script src="E:/testJS/localscript.js"type="text/javascript"></script>
   
</head>
<body>
<input onclick="HelloWorldLocal();" type="button" value="Say Hello!"/>
</body>
</html>

Open in new window


JavaScript File
function HelloWorldLocal()
{
alert("Hello World");
}

Open in new window

Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Hi, why do you want to put a physical path and not a relative one? Ie create a folder js in your virtual directory and put the file in there. Then reference it as /js/jsfilename.js

Giannis
Why would you want to do this - the page will only work on machines that have the library in exactly the same path - makes no sense?

Give us some insight as to why you would want to do this?

It is failing probably because of the same domain policy - you are getting the page from the server which is recognised as a different domain from your local machine and therefore is blocked.

The correct procedure is to place the javascript file somewhere in the webroot of the website and refer to it by its relative or server based path

i.e
src="js/filename.js"

OR

src="http://website/js/filename.js"
You have proven that your IIS 7.5 is working properly.  The 'user' for the web server is a very limited user that does not have access permissions outside the web root directories.  It worked on your own machine because you were not running thru a web server which means that you were running under the permissions of your own user.
Avatar of wael_shehab

ASKER

Hi,
i want to do the same mentioned setup for some security reasons
as i have some well written JS library and i want to hide it from the end user of my web site
so i though it would be great to put it on a non web site path like D:\test  and any JS file in the web site will call the D:\test   library
----------------------
now i  want to skip this iis security role to reach my target.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
No matter how well written you may think it is I bet hundreds/thousands more have written the almost exact same thing
Apart from what Dave has said, what you are ending up doing is trying to load the file from the clients own computer with the link path which is what the error message is telling you because you cannot.
There's a few options in the link below, some of them work really well :o/
http://rainbow.arch.scriptmania.com/scripts/no_right_click.html
You funny, Gary...