Stop backslash behaving as the escape character 
Author Message
 Stop backslash behaving as the escape character

I'm using a product which generates HTML from a template I
have written.  One of the many pieces of text this product
inserts in the template is a (Windows) directory path
complete with backslashes.  This would be ok, but I need
to process this path by passing the string to a JScript
function.  An example of this:

template: <div onclick = "processPath(' ~~PATH~~ ');">

becomes: <div onclick = "processPath('H:/web/abc/...'); ">

The problem is by the time I get hold of this in JScript
the backslashes are interpreted as the escape character
and the path string is incorrect.

I would be grateful for any help,

David.

(remove the "REMOVE"s from my email to contact me)



Fri, 16 Dec 2005 18:10:00 GMT  
 Stop backslash behaving as the escape character

Quote:
> I'm using a product which generates HTML from a template I
> have written.  One of the many pieces of text this product
> inserts in the template is a (Windows) directory path
> complete with backslashes.  This would be ok, but I need
> to process this path by passing the string to a JScript
> function.  An example of this:

> template: <div onclick = "processPath(' ~~PATH~~ ');">

> becomes: <div onclick = "processPath('H:/web/abc/...'); ">

> The problem is by the time I get hold of this in JScript
> the backslashes are interpreted as the escape character
> and the path string is incorrect.

> I would be grateful for any help,

> David.

> (remove the "REMOVE"s from my email to contact me)

A number of solutions depending on how the paths are retrieved. If you can
pre-process the paths then double up all backslashes before entering the
text into the html:
var sPath = getPath();  //returns a path such as 'C:\myFolder\myDocs'
var sProcessedPath = sPath.replace(/\\/, \\\\);

if this is not possible then change the div to become:

template:
<div path="~~PATH~~"
onclick="processPath(this.getAttribute('path'));"></div>
becomes:
<div path="c:\myFolder\myDocs"
onclick="processPath(this.getAttribute('path'));"></div>

Attribute values are not JavaScript so do not need escaping.

--

Joe



Fri, 16 Dec 2005 18:34:20 GMT  
 Stop backslash behaving as the escape character

Quote:


> > I'm using a product which generates HTML from a template I
> > have written.  One of the many pieces of text this product
> > inserts in the template is a (Windows) directory path
> > complete with backslashes.  This would be ok, but I need
> > to process this path by passing the string to a JScript
> > function.  An example of this:

> > template: <div onclick = "processPath(' ~~PATH~~ ');">

> > becomes: <div onclick = "processPath('H:/web/abc/...'); ">

> > The problem is by the time I get hold of this in JScript
> > the backslashes are interpreted as the escape character
> > and the path string is incorrect.

> > I would be grateful for any help,

> > David.

> > (remove the "REMOVE"s from my email to contact me)

> A number of solutions depending on how the paths are retrieved. If you can
> pre-process the paths then double up all backslashes before entering the
> text into the html:
> var sPath = getPath();  //returns a path such as 'C:\myFolder\myDocs'
> var sProcessedPath = sPath.replace(/\\/, \\\\);

> if this is not possible then change the div to become:

> template:
> <div path="~~PATH~~"
> onclick="processPath(this.getAttribute('path'));"></div>
> becomes:
> <div path="c:\myFolder\myDocs"
> onclick="processPath(this.getAttribute('path'));"></div>

> Attribute values are not JavaScript so do not need escaping.

> --

> Joe

Sorry example one should read:
var sPath = getPath();  //returns a path such as 'C:\myFolder\myDocs'
var sProcessedPath = sPath.replace(/\\/, "\\\\");

--

Joe



Fri, 16 Dec 2005 23:15:08 GMT  
 Stop backslash behaving as the escape character
Thank you very much Joe, using the div attribute method
solved the problem completely.

Quote:
>-----Original Message-----





>> > I'm using a product which generates HTML from a
template I
>> > have written.  One of the many pieces of text this
product
>> > inserts in the template is a (Windows) directory path
>> > complete with backslashes.  This would be ok, but I
need
>> > to process this path by passing the string to a
JScript
>> > function.  An example of this:

>> > template: <div onclick = "processPath(' ~~PATH~~ ');">

>> > becomes: <div onclick = "processPath

('H:/web/abc/...'); ">
Quote:

>> > The problem is by the time I get hold of this in
JScript
>> > the backslashes are interpreted as the escape
character
>> > and the path string is incorrect.

>> > I would be grateful for any help,

>> > David.

>> > (remove the "REMOVE"s from my email to contact me)

>> A number of solutions depending on how the paths are

retrieved. If you can
Quote:
>> pre-process the paths then double up all backslashes
before entering the
>> text into the html:
>> var sPath = getPath();  //returns a path such

as 'C:\myFolder\myDocs'

- Show quoted text -

Quote:
>> var sProcessedPath = sPath.replace(/\\/, \\\\);

>> if this is not possible then change the div to become:

>> template:
>> <div path="~~PATH~~"
>> onclick="processPath(this.getAttribute('path'));"></div>
>> becomes:
>> <div path="c:\myFolder\myDocs"
>> onclick="processPath(this.getAttribute('path'));"></div>

>> Attribute values are not JavaScript so do not need
escaping.

>> --

>> Joe

>Sorry example one should read:
>var sPath = getPath();  //returns a path such

as 'C:\myFolder\myDocs'

- Show quoted text -

Quote:
>var sProcessedPath = sPath.replace(/\\/, "\\\\");

>--

>Joe

>.



Fri, 23 Dec 2005 20:23:07 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. escaping backslashes

2. Q. Escape Character For Response.Write

3. escaping special characters

4. Escape SQL-wildcard character(%)

5. Escape characters

6. need help with regexp and \ escape character

7. Cookies & Character Escape

8. exec.vbs within a vbscript (escaping characters)

9. Escape character for VBScript Write function

10. document.write method and escape characters

11. An Easy one: escape characters in VBscript

12. Escape Character for 'Replace' Function

 

 
Powered by phpBB® Forum Software