I have a Javascript bookmarklet that, when clicked on, redirects the user to a new webpage and supplies the URL of the old webpage as a parameter in the query string.
I'm running into a problem when the original webpage has a double hyphen in the URL (ex. page--1--of--3.html
). Stupid, I know - I can't control the original page The javascript escape
function I'm using does not escape the hyphen, and IIS 6 gives a file not found error if asked to serve resource.aspx?original=page--1--of--3.html
Is there an alternative javascript escape function I can use? What is the best way to solve this problem? Does anybody know why IIS chokes on resource.aspx?original=page--1
and not page-1
?
I have a Javascript bookmarklet that, when clicked on, redirects the user to a new webpage and supplies the URL of the old webpage as a parameter in the query string.
I'm running into a problem when the original webpage has a double hyphen in the URL (ex. page--1--of--3.html
). Stupid, I know - I can't control the original page The javascript escape
function I'm using does not escape the hyphen, and IIS 6 gives a file not found error if asked to serve resource.aspx?original=page--1--of--3.html
Is there an alternative javascript escape function I can use? What is the best way to solve this problem? Does anybody know why IIS chokes on resource.aspx?original=page--1
and not page-1
?
- have you checked the server logs to see what it is recieving a request for? – Breton Commented Jun 17, 2009 at 5:42
4 Answers
Reset to default 4"escape" and "unescape" are deprecated precisely because it doesn't encode all the relevant characters. DO NOT USE ESCAPE OR UNESCAPE. use "encodeURIComponent" and "decodeURIComponent" instead. Supported in all but the oldest most decrepit browsers. It's really a huge shame this knowledge isn't much more mon.
(see also encodeURI and decodeURI)
edit: err just tested, but this doesn't really cover the double hyphens still. Sorry.
Can you expand the escape function with some custom logic to encode the hypen's manually?
resource.aspx?original=page%2d%2d1%2d%2dof%2d%2d3.html
Something like this:
function customEscape(url) {
url = escape(url);
url = url.replace(/-/g, '%2d');
return url;
}
location.href = customEscape("resource.axd?original=test--page.html");
Update, for a bookmarklet:
<a href="javascript:location.href=escape('resource.axd?original=test--page.html').replace(/-/g, '%2d')">Link</a>
You're doing something else wrong. -- is legal in URLs and filenames. Maybe the file really isn't found?
-- is used to ment out text in a few scripting languages. SQL Server uses it to add ments. Do you use any database logic to store those filenames? Or create any queries where this name is part of the query string instead of using query parameters?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742288008a4415672.html
评论列表(0条)