Getting Absolute path in Javascript

M

mhadi

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
 
M

Martin Honnen

mhadi wrote:

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.

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/d...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/d...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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top