Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple problem with location.href.replace

    Hi,

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

    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

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

    http://dev.xyz.com/sites/testsite/_l.../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,

    Code:
    <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...
    Any help is verymuch appreciated...

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...llItems%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.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •