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 to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Problem with window.location

    Hello everyone,

    For an application at work, I'm creating a page that redirects to another page and passes variables as Querystrings.

    The problem is, once I create my link and open it, I do not get the desired result.
    In this example :

    document.write(test); ---> gives me the url
    window.location.href = test; ---> completely changes the link given in document.write(test) ---> KWInst doesn't return 30 but gives something like <span name="_P_SUM3" .... />

    So I guess my question is, how to I open a window where the URL = the result of "document.write(test)" ? I can't directly pass the variables in javascript or else the variables just return a <span> in the link...

    Any ideas ?

    Thanks a lot

    Nico


    Code:
    <script type="text/javascript">
    
    
        document.write(sysvar("_wh_V[0]"));
        document.write(sysvar("_wh_V[4]"));
        document.write(sysvar("_pln[0]"));
        document.write(sysvar("_P_SUM3"));
    
        var KWInst = sysvar("_P_SUM3");
        var KWhCumul = sysvar("_wh_V[4]");
        var link = "http://193.5.225.25/GetData.aspx?DataLoad=Yes&KWInst=";
        var linktwo = "&KWhCumul=";
    
        var test = link + KWInst + linktwo + KWhCumul;
    
        window.location.href = test;
    
    </script>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,857
    Thanks
    78
    Thanked 4,417 Times in 4,382 Posts
    Ummm...for starters, stop using document.write. Not only is it very obsolete, but it has the horrible property that, if you use it after a page is fully loaded, it WIPES OUT all current content on the page, including the JavaScript used to do the the document.write.

    But anyway...I suspect that you are fooling youself.

    Let's suppose that sysvar("_P_SUM3") actually contains <span name="_P_SUM3" class="zamboni">30</span>

    If you then document.write that to the screen, what do you think you will see?

    HINT: You will *NOT* see <span name="_P_SUM3" class="zamboni">30</span>

    Instead, you will see simply 30

    The HTML tags DISAPPEAR!

    If you want to see what it *REALLY* contains, you could do
    Code:
    document.write( sysvar("_P_SUM3").replace("<","&lt;");
    or maybe
    Code:
    document.write( "<pre>" + sysvar("_P_SUM3") + "</pre>" );
    So no suprise that when you dump that into the HREF you get what you think is garbage but what is actually the correct contents of the whatever-the-heck-sysvars is.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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