...

View Full Version : Simple problem with location.href.replace



spswss
12-22-2005, 04:43 PM
Hi,

I am facing a very simple problem, I have a URL like this,

http://dev.xyz.com/sites/testsite/_layouts/1033/Reorder.aspx?List=%7b9DF6D1C1%2d71B4%2d4380%2d9278%2dCAD739F6A34A%7d&Source=http%3A%2F%2Fdev%2Exyz%2Ecom%2Fsites%2Ftestsite%2FLists%2FNewList%2FAllItems%2Easpx

Whenever user gets to this URL, the URL needs to change like this,

http://dev.xyz.com/sites/testsite/_layouts/1033/Reorder.aspx?List={9DF6D1C1-71B4-4380-9278-CAD739F6A34A}&Source=http%3A%2F%2Fdev%2Exyz%2Ecom%2Fsites%2Ftestsite%2FLists%2FNewList%2FAllItems%2Easpx

ie,
%2d should change to -
%7b should change to { &
%7d should change to }

I am trying it like this,


<script>
function InitPage()
{
location.href = location.href.replace('\%2d', "-");
location.href = location.href.replace('\%7b', "{");
location.href = location.href.replace('\%7d', "}");
}
</script>

<BODY marginwidth=0 marginheight=0 scroll="yes" onload="InitPage();">

With this the page keeps on refreshing continuosly... :confused:
Any help is verymuch appreciated... :thumbsup:

rlemon
12-22-2005, 08:03 PM
thats because you cannot unescape those characters in the url . hence why they are encoded in unicode.

if you wish to return these values to read later run the replace after you return them - not in the url

whats happening:


location =
http://dev.xyz.com/sites/testsite/_l.../Reorder.aspx?List=%7b9DF6D1C1%2d71B4%2d4380%2d9278%2dCAD739F6A34A%7d&Source=http%3A%2F%2Fdev%2Exyz%2Ecom%2Fsites%2Ftestsite%2FLists%2FNewList%2FAllItems%2Easpx

location.href = location.href.replace('\%2d', "-");

page reloads changing the characters %2d to simply '-'

then the browser takes over and converts the '-' character to %2d

now at this point your init script will hit again and replace the same characters in the url. - therefore reloading the document and starting the loop again.

i suggest

var url = location.href;
url = url.replace('\%2d,'-');
url = url.replace('\%7b,'{');
url = url.replace('\%7d,'}');

then work with the variable url.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum