Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 18th, 2004, 10:29 PM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default lost slashes when passing in param

I'm trying to pass a path (i.e. C:\My Pictures\) as a parameter to a function and when it reaches the function the slashes are gone. I know in PHP there are built in functions to alleviate this - does javascript have a way to do this? Here's an example of what I'm trying to do.

I have a dynamic page that's primarily PHP and pulls info out of a MySQL database, one of them being a path to a picture. I use a hyperlink to call a function that opens a new window to display the picture. So in the call it onClick="showPic($PicturePath)" - $PicturePath being the PHP variable that holds the path. By viewing source I can tell that the slashes are still there at that point. The function is something like

function showPic(picPath) {
  var picWindow = window.open('', 'qcid')
  picWindow.document.open();
  picWindow.document.write('<img src="' + picPath + '" border="0">');
  picWindow.document.close();
}

The windows opens but the image source path is missing all the slashes - so if it was C:\My Pictures\image.gif originally then by the time it hits the new window it's C:My Documentsimage.gif. Any help would be much appreciated.

Thanx!
Bob

Reply With Quote
  #2 (permalink)  
Old August 19th, 2004, 01:40 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

I think you need to encode the string which is passed.

Om Prakash
Reply With Quote
  #3 (permalink)  
Old August 19th, 2004, 07:12 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You must escape the slashes by doubling them up:
C:\\myFolder\\myPic.jpg
I don't know if there's a php function to do that.
Alternatively write the path to a hidden form element with a known name and use that as you functions argument:
Code:
<input type="hidden" name="filePath" value="$PicturePath">
showPic(document.forms[0].filePath.value);
--

Joe
Reply With Quote
  #4 (permalink)  
Old August 19th, 2004, 10:33 AM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 You must escape the slashes by doubling them up:
C:\\myFolder\\myPic.jpg
I don't know if there's a php function to do that.
Alternatively write the path to a hidden form element with a known name and use that as you functions argument:
Code:
<input type="hidden" name="filePath" value="$PicturePath">
showPic(document.forms[0].filePath.value);
--

Joe
Thank you Joe!

PHP has a built in function, addslashes(), which doubles up the slashes, and this worked beautifully! Got any suggestions for my other post about opening a file browse dialog to a specified location?

Thanks again!
Bob

Reply With Quote
  #5 (permalink)  
Old August 20th, 2004, 06:08 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

As far as I know it is impossible due to security restrictions. Not sure why it impinges on security but that was the answer from a Microsoft person when I asked them this many years ago.

--

Joe
Reply With Quote
  #6 (permalink)  
Old August 20th, 2004, 10:01 AM
Authorized User
 
Join Date: Nov 2003
Location: Phoenix, AZ, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 As far as I know it is impossible due to security restrictions. Not sure why it impinges on security but that was the answer from a Microsoft person when I asked them this many years ago.

--

Joe
I had heard that as well, which does make sense, but doesn't solve my problem :) I'll just have to find another solution, thanks again!


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Node as a Param from javascript to XSL pnviv XSLT 4 November 15th, 2007 05:57 AM
passing param to Crystal hide4motion C# 0 October 23rd, 2005 03:32 PM
add slashes and strip slashes madhukp PHP How-To 6 December 27th, 2004 05:37 AM
passing param to XSLT Dangerous Dave XSLT 0 April 30th, 2004 07:46 PM



All times are GMT -4. The time now is 10:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.