Javascript window.prompt 变量包含反斜杠
我有一个包含超链接(自然地)的页面,这些超链接是从 SQL 表构建的,但某些超链接实际上是网络资源(即 \server\path)。对于这些,我设置了一个 jQuery 语句来查找它们,并将这些 标记替换为
else if (($link.length > 0) && ($link.substring(0, 4) != "http")) {
$('.linktext', $this.closest('tr')).after("<span><a href='#link' onclick='window.prompt(\"This resource is located on a network drive and is not accessible via the web browser. Please copy the link and paste into Windows Explorer.\",\""+$link+"\");'>Text</a></span>");
}
提示有效,但文本区域看起来与此完全相同 \serverfolder1folder2file.ext
I have a page with hyperlinks (naturally) that are constructed from a SQL table but some of the hyperlinks are actually network resources (i.e. \server\path). For those I set up a jQuery statement to find them and replace those <a href>
tags with <a onclick='window.prompt...>
so that the network location will be in the textbox of the prompt then users can copy it and paste it into Windows Explorer. The problem is, all the backslashes are being removed. I know you usually have to escape them with double backslashes I'm not putting the paths in manually, they're coming from the SQL table and I'm putting them into the prompt using a variable. Can anyone tell if there's a solution?
else if (($link.length > 0) && ($link.substring(0, 4) != "http")) {
$('.linktext', $this.closest('tr')).after("<span><a href='#link' onclick='window.prompt(\"This resource is located on a network drive and is not accessible via the web browser. Please copy the link and paste into Windows Explorer.\",\""+$link+"\");'>Text</a></span>");
}
The prompt works but the text area will look exactly like this \serverfolder1folder2file.ext
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用两个反斜杠而不是一个:
\\server\\path
。JavaScript 字符串/正则表达式中的反斜杠具有作为转义字符的特殊含义:
Use two backslashes instead of one:
\\server\\path
.A backslash inside JavaScript strings/Regular expressions have the special meaning of being an escape character:
mysql_real_escape_string()
是您的解决方案。因此,在将服务器值传递
回客户端之前,只需转义服务器值即可。
mysql_real_escape_string()
is your solution.outputs
So just escape your server values before your pass them back to the client.
我只是想到了一个简单的解决方案,可以在从 SQL 加载 URL 值后对其进行“转义”。这样我就可以有选择地定位要转义的内容并保留正常的 http URL:
I just thought of a simple solution that can "escape" the URL values after they've been loaded from SQL. This way I can selectively target what to escape and leave the normal http URL's as they are: