I have an application which parses strings and passes them via jQuery to a popup window. Some of the strings I am passing contain a field for web addresses OR internal C: drive locations. When I pass the string to the window, the backslash (“\”) from the windows path is being stripped out (the web addresses using the forwardslash is, of course, no problem. I am trying to pass these strings as links, so the user can just click on the link and off they go. Obviously, if the backslashes are stripped, the link does not work. How the heck do I test for this? I have tried a few simple regexes that don’t work.
EDIT: The strings that I am parsing come from a Sharepoint list of applications, and I have no control over their format, they are simply entered into the list as “\drive\then\the\path\to\the\file”. My understanding is that I need to check to see if there is a backslash, then escape it by adding another backslash. But how?
EDIT 2: Good to know that I was on the right track. From what I had read on the internets, I had figured it was something along this line. However, I still can’t get this to work. Maybe you folks could help me out….
I have grabbed the field from the sharepoint list like this (sharepoint stores field names with a prefix of ‘ows_’:
var devPath = "<a class='h_link' href='"+$(this).attr('ows_DEVPathURLServer')+"'>"+$(this).attr('ows_DEVPathURLServer')+"</a>";
This works great for web URLs, as stated.
So then I messed around with doing a .replace(/\/g,’\\’);, but it won’t run. So then I thought I would try:
var unregged = $(this).attr('ows_DEVPathURLServer');
var regged = unregged.toString().split('\\').join('\\\\');
alert(regged);
var devPath = "<a class='h_link' href='"+regged+"'>"+regged+"</a>";
Just to break down my thought process. Doesn’t work. What am I missing?
Thanks!
You can simply check if this is location that is “local” and convert it to File URI scheme prior to passing it further.
Something like this may do the trick:
This should convert
\d\then\the\path\to\the\filetofile:///d:/then/the/path/to/the/file