p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   lost slashes when passing in param (http://p2p.wrox.com/showthread.php?t=17088)

bleitner August 18th, 2004 10:29 PM

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


om_prakash August 19th, 2004 01:40 AM

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

Om Prakash

joefawcett August 19th, 2004 07:12 AM

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

bleitner August 19th, 2004 10:33 AM

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


joefawcett August 20th, 2004 06:08 AM

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

bleitner August 20th, 2004 10:01 AM

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!




All times are GMT -4. The time now is 01:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.