473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Getting Absolute path in Javascript

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
2 21241


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: William Starr Moake | last post by:
Another problem with absolute paths in the WYSIWYG editor I'm putting together. The function to toggle between WYSIWYG and HTML modes works except for one glitch. If you use a relative path for...
2
by: gonzalez | last post by:
Hi, I'm trying to get the absolute xpath to a node in DOM (XmlDocument). I know I can build it by warlking the tree recursively, but I'm wondering if there is an API in DOM or in XPathNavigator...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
4
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
2
by: Radu | last post by:
Hi. I have files in the "Scorecard Previews" subfolder of the virtual path of my app, the absolute path being C:\Data\Ordering Process\Scorecard Previews\ I have a javascript function...
7
by: raylaur | last post by:
I'm using a javascript "slide" function to move a <div> layer in 10 pixel increments from one location on a page to another. The layer contains a GIF image. It's basically a side panel that flies out...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
0
by: BruceMcF | last post by:
On Apr 16, 6:03 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.