By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,704 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,704 IT Pros & Developers. It's quick & easy.

Getting Absolute path in Javascript

P: n/a
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

Dec 26 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


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/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/
Dec 26 '05 #2

P: n/a
On 2005-12-26, mhadi <ma********@gmail.com> wrote:

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


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
Dec 26 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.