473,382 Members | 1,717 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,382 software developers and data experts.

Javascript \ Escape problem

Greetings,

I have some javscript mixed into a applications templating and have
run into a problem the way javascript is handling a path for me.

I am via the template assigning a file path to a javascript variable.

The Tempalte: var myfile = "!FILEPATH!";
which becomes: var myfile = "C:\mydir\thefile.txt";

The issue of course being that the \'s are not escaped. I'm not as
fluent in Javascript as I'd like to be yet and I havn't figured out a
way to escape it so I can coninue on with the rest of the script.
I've tried to do a search and replace but javscript is already
interpreting the \'s as escaping a character.

How can I either autoescape the \'s (if possible), or access the raw
data so I can replace \ with \\?

Any help is appriciated.

Thanks!

BlueMac
Jul 20 '05 #1
2 7090
> I am via the template assigning a file path to a javascript variable.

The Tempalte: var myfile = "!FILEPATH!";
which becomes: var myfile = "C:\mydir\thefile.txt";

The issue of course being that the \'s are not escaped. I'm not as
fluent in Javascript as I'd like to be yet and I havn't figured out a
way to escape it so I can coninue on with the rest of the script.
I've tried to do a search and replace but javscript is already
interpreting the \'s as escaping a character.

How can I either autoescape the \'s (if possible), or access the raw
data so I can replace \ with \\?


You have to do the \ correction before it gets handed to JavaScript.

Jul 20 '05 #2
BlueMac wrote:
I am via the template assigning a file path to a javascript variable.

The Tempalte: var myfile = "!FILEPATH!";
which becomes: var myfile = "C:\mydir\thefile.txt";

How can I either autoescape the \'s (if possible), or access the raw
data so I can replace \ with \\?


I'm assuming the JavaScript is being run inside an HTML document? If
so, and you know the browser will support the DOM standard, try

<meta name="FILEPATH" content="!FILEPATH!" />

in the <head>, and

var i, myfile;
var metas = document.getElementsByTagName("meta");

for (i = 0; i < metas.length; i++)
if (metas.item(i).getAttribute("name") == "FILEPATH") {
myfile = metas.item(i).getAttribute("content");
break;
}

in the script.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gary Mayor | last post by:
Hi, If I have the ' character within the javascript:pick command it doesn't work. Is there some sort of way of escaping these characters like in server side languages. function pick(symbol) {...
3
by: NecroJoe | last post by:
I am using PHP to generate a little javascript for one of my pages. In short it allows a user to select a value from a list and pop it into a form field on a seperate page. This works well unless...
7
by: Richard Trahan | last post by:
I need a javascript function to hex-encode a plus sign so I can pass the plus sign as an argument in a GET request. escape() and encodeURI() don't do it (and probably shouldn't, because '+' is a...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
7
by: annoyingmouse | last post by:
Is it possible to use javascript to add javascript to a DOM object? I've the following code to add an image to a page: function flagError(id){ var image = document.createElement('img');...
10
by: korund | last post by:
We can use special characters ('\n') to add line breaks in text in JavaScript popup Alert boxes. there is also few additional special characters: \' single quote \" double quote \&...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.