Reputation: 9162
I'm trying to link to the directory above the web root, but it doesn't work in JavaScript. It doesn't matter how many ../
I use, it doesn't go more than twice, which is required to reach the web root. (Using PHP this works fine, though) I think it should be possible right? Could it be a permission problem? Thanks.
Upvotes: 0
Views: 269
Reputation: 700322
You can't link to a folder above the web root, because it simply doesn't exist.
You link to a web resource, not a physical folder. This resource usually corresponds to a file or folder stored physically on the server, but it doesn't have to. When it does correspond to a file or folder in the file system, it's only folders under the folder corresponding to the web root that is a part of the resources in that web. Anything above the folder is simply not part of the web. Eventhough it exists in the file system, it doesn't exist as a web resource.
Upvotes: 0
Reputation: 873
Javascript works on the client side. Client side doesn't know anything about the fylesystem of server so can't know or access anything there - client's root is domain name and adding one more '..' means trying to dive above domain name, not above one level in filesystem.
Upvotes: 0
Reputation: 2817
If you want to reach website root name, It's here:
var root = location.protocol + '//' + location.host;
//For a url, let say 'http://google.com/ig', it will return 'http://google.com'
But, Christian Stieber's answer is right If you want to reach any of server's file.
Upvotes: 0
Reputation: 12496
JavaScript is clientside -- it runs on the browser, not the server. A correctly set up server will not let clients access stuff outside the designated area, independent of whether it's from entering an URL into the addressbar, a link contained in an HTML page, or a URL created by JavaScript. It's all the same for the server anyway -- it's just an URL.
Upvotes: 2