Click to See Complete Forum and Search --> : Get Absolute Path With Script


Nazz
01-05-2003, 12:07 PM
I'm using a window.open("file:///...") statement to open a local file in a new window, but realize that others will have the file in different directories, and would like to know how to get the window.open or equivelent to open a file that is locate in the same folder as the html page that is calling it, or a script that will locate the absolute path of the html that is calling it.

thanks

pyro
01-05-2003, 12:23 PM
<script type="text/javascript">
document.write (document.location);
</script>

This will print the current location to your screen. Hopefully you can modify it to suit your needs.

Why not use a relative path, though? Somthing like folder/page.htm?

Nazz
01-05-2003, 05:45 PM
Well, here's what I"ve come up with so far:

var url = document.location.href ;
var myiepath=url.substring(8,url.length-12);
onload=window.open("file:///" + myiepath + "edit.htm")

I used the document.location to get the full path and name of the script file, and used the substring to remove the name of the file then add the name of the file I want it to open in a new window.

this works fine as long as I manually load the page with the script, but when I have a plugin load it, it grabs the path from the current window that is loaded, and if no window is loaded it tries to use the about:blank as the path. any other suggestions?

thanks

Nazz
01-05-2003, 06:22 PM
Originally posted by Dave Clark
I'd like to know why you're wanting to "mess with" the visitor's harddrive?

Dave

heh, nice way to put it, but actually, it is a plugin that I am working on for the MyIE Browser.

I created an editableContent notepad page, and it works nice, but trying to get it to load as a plugin, when you click the button on the tool bar, it will open the notepad in a window.open statement. it works fine if I manually load the local path in the address bar, but having problems getting it to load from the toolbar button.

Nazz
01-05-2003, 06:31 PM
Originally posted by pyro
<script type="text/javascript">
document.write (document.location);
</script>

Why not use a relative path, though? Somthing like folder/page.htm?

Pyro, the reason I don't want to use a relative path to the file is because MyIE does not have an install, you create a folder and unzip where you want, so I have no idea where they are putting it on their hard drive. if I use the file:///c|/program%20files/... it works great, for me, and anyone who happens to have it in the same folder. Otherwise if anyone else wanted to use this plugin, they would have to manually edit the path manually in the file, but I"m trying to make it as easy as possible for anyone who would like to use this plug.

pyro
01-05-2003, 06:38 PM
I see... I don't know what to tell you if you the code I gave you doesn't work with your plugin.

Nazz
01-10-2003, 12:19 AM
Originally posted by Dave Clark
If the currently loaded HTML page is loaded using the file:// protocol, then the following JavaScript (in that same HTML page) will open another HTML page in the same folder:


var path = top.location.pathname;
if (document.all) {
path = path.replace(/\\/g,"/");
}
path = path.substr(0,path.lastIndexOf("/")+1);
var url = top.location.protocol + "//" + path + "edit.htm";
window.open(url, "name", "...features...");


Dave

Thanks dave, this almost works, but only problem with the plugin is that when I click the button, it only reads the script in the page, rather than loading the page into the browser. if I load the page manually then it grabs the current path calls the edit.htm with no problem since it is getting the path from the page, but being that it is not loaded, the path is read from the page that is currently loaded or the about:blank page that I use as my start page.

is there a way to find the "current path" of it's self (the location of the file which contains the script), rather than looking to the top.location?

Thanks