Connecting Tech Pros Worldwide Forums | Help | Site Map

Getting Absolute path in Javascript

mhadi
Guest
 
Posts: n/a
#1: Dec 26 '05
Hi All,
I am developing a solutions for clients to run some webpages. Since
there is no webserver the ASP route is a No Go. So I am using
Javascript to connect to my database.
The Problem is that the following Connection string
var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb";
Search of Data.mdb on the desktop.

I came to know that this requires absolute path i.e
var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Folder1\Data.mdb";

But the problem is the web pages will be distributed on CD and drive
name may differs. Further more if the user copies the pages to the hard
disk it may stop working.

I want to know how can I get the absolute path, in ASP we use
Server.MapPath but what function to use in javascript only version?

Thanks in advance
mhadi


Martin Honnen
Guest
 
Posts: n/a
#2: Dec 26 '05

re: Getting Absolute path in Javascript




mhadi wrote:

[color=blue]
> I am developing a solutions for clients to run some webpages. Since
> there is no webserver the ASP route is a No Go. So I am using
> Javascript to connect to my database.[/color]

JavaScript can be used in several contexts, we need to know which
context you use. Do you use it as script embedded in HTML documents that
you load locally from the file system in a browser? Do you use it as a
Windows Script Host script to be executed on Windows? Do you use it in a
HTML application, a HTA? Windows Script Host and/or HTA is usually a way
to have script with full rights and with file system access, with data
base access.
For instance in a Windows Script Host file you can get the current
directory your script is being executed in
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/a36f684c-efef-4069-9102-21b3d1d55e9e.asp>
That also works in a HTA e.g.

<html>
<head>
<title>Current directory</title>
<script type="text/jscript">
window.onload = function () {
try {
var wshShell = new ActiveXObject('WScript.Shell');
document.body.appendChild(
document.createTextNode('Current directory is: ' +
wshShell.CurrentDirectory + '. ')
);
}
catch (e) {
document.body.appendChild(
document.createTextNode('No access to WScript.Shell: ' + e.message)
)
}
}
</script>
</head>
<body>
</body>
</html>

With a normal HTML document loaded in IE you will run into security
problems, in particular on Windows XP Service Pack 2 and later with
local file system lockdown done there by default.

Windows Script Host docs are online here on MSDN:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/d78573b7-fc96-410b-8fd0-3e84bd7d470f.asp>

HTA docs here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/hta/hta_node_entry.asp>


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jasen Betts
Guest
 
Posts: n/a
#3: Dec 26 '05

re: Getting Absolute path in Javascript


On 2005-12-26, mhadi <mabdulhadi@gmail.com> wrote:

[color=blue]
> Hi All,
> I am developing a solutions for clients to run some webpages. Since
> there is no webserver the ASP route is a No Go. So I am using
> Javascript to connect to my database.
> The Problem is that the following Connection string
> var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb";
> Search of Data.mdb on the desktop.
>
> I came to know that this requires absolute path i.e
> var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\Folder1\Data.mdb";
>
> But the problem is the web pages will be distributed on CD and drive
> name may differs. Further more if the user copies the pages to the hard
> disk it may stop working.
>
> I want to know how can I get the absolute path, in ASP we use
> Server.MapPath but what function to use in javascript only version?
>
> Thanks in advance
> mhadi[/color]

The value window.location.pathname will tell you where the current HTML
page was loaded from.
it should be possible to cut the tail off that and then add the path to the
database file.

Bye.
Jasen
Closed Thread