admin管理员组文章数量:1392086
I am trying to link to a file that has the '#' character in via a window.open() call. The file does exist and can be linked to just fine using a normal anchor tag.
I have tried escaping the '#' character with '%23' but when the window.open(myurl) gets processed, the '%23' bees '%2523'. This tells me that my url string is being escapped by the window.open call changing the '%' to the '%25'.
Are there ways to work around this extra escaping.
Sample code:
<script language="javascript">
function escapePound(url)
{
// original attempt
newUrl = url.replace("#", "%23");
// first answer attempt - doesn't work
// newUrl = url.replace("#", "\\#");
return newUrl;
}
</script>
<a href="#top" onclick="url = '\\\\MyUNCPath\\PropertyRushRefi-Add#1-ABCDEF.RTF'; window.open(escapePound(url)); return true;">Some Doc</a>
URL that yells says "file://MyUNCPath/PropertyRushRefi-Add%25231-ABCDEF.RTF" cannot be found
I am trying to link to a file that has the '#' character in via a window.open() call. The file does exist and can be linked to just fine using a normal anchor tag.
I have tried escaping the '#' character with '%23' but when the window.open(myurl) gets processed, the '%23' bees '%2523'. This tells me that my url string is being escapped by the window.open call changing the '%' to the '%25'.
Are there ways to work around this extra escaping.
Sample code:
<script language="javascript">
function escapePound(url)
{
// original attempt
newUrl = url.replace("#", "%23");
// first answer attempt - doesn't work
// newUrl = url.replace("#", "\\#");
return newUrl;
}
</script>
<a href="#top" onclick="url = '\\\\MyUNCPath\\PropertyRushRefi-Add#1-ABCDEF.RTF'; window.open(escapePound(url)); return true;">Some Doc</a>
URL that yells says "file://MyUNCPath/PropertyRushRefi-Add%25231-ABCDEF.RTF" cannot be found
Share Improve this question edited Oct 24, 2008 at 15:31 munity wiki2 revs
shrub34 1
- Can you give an example of the code? – StingyJack Commented Oct 24, 2008 at 15:27
4 Answers
Reset to default 6You seek the dark magicks of encodeURI:
window.open("http://your-url./" + encodeURIComponent("foo#123.jpg"));
Did you try using the standard text escape char "\"?
\#
Have you tried URL encoding via JavaScript as done here and here?
Have you tried not escaping the url?
<a href="#top onclick="url = '\\\\MyUNCPath\\PropertyRushRefi-Add#1-ABCDEF.RTF'; window.open(url); return true;">Some Doc</a>
本文标签: url rewritingjavascript windowopen() andsymbolStack Overflow
版权声明:本文标题:url rewriting - javascript window.open() and # symbol - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780761a2624697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论