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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to pass along a url parameter to any links clicked?

    Hi, I have an "offline" html demo of 50+page - so it needs to run on standard html/javascripts...

    I'm trying to do this:

    Page A
    Code:
    <a href="pageb.html?endpage=pageD.html">Page B.html</a>
    <a href="pageb.html?endpage=pageE.html">Page B.html</a>
    <a href="pageb.html?endpage=pageF.html">Page B.html</a>
    Page B
    Code:
    <a href="PageC.html?endpage=(the parameter of page A)">Page C</a>
    <a href="(the parameter of page A)">End Page</a>
    Page C
    Code:
    <a href="(the parameter of page A)">End Page</a>
    I've searched for a couple of hours already and I just can't seem to find this... I'm not that great at javascripts... Thanks a lot!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Well, the general way you get the value of a parameter is this:

    Code:
    <script type="text/javascript">
    var pageParams = [];
    if ( location.search.length > 1 ) 
    {
        var pairs = location.search.substring(1).split("&");
        for ( var p = 0; p < pairs.length; ++p )
        {
            var pair = pairs[p].split("=");
            if ( pair.length > 0 )
            {
                 pageParams[ pair[0] ] = decodeURIComponent( pair[1] );
            }
        }
    }
    </script>
    Now, any time you need that value of a querystring parameter, you just code
    Code:
         pageParams["endpage"]
    (as an example).

    So you could, for example, create the <A> tags you wanted thus:
    Code:
    <script type="text/javascript">
    document.write('<a href="PageC.html?endpage=' + pageParams["endpage"] + '">Page C</a>');
    ...
    document.write('<a href="' + pageParams["endpage"] + '">End Page</a>');
    ...
    </script>
    But there are other ways to do the equivalent, using DOM modifications instead of document.write.

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    1000 thanks. It's exactly what I was looking for. Works perfectly. Once again, thank you.


  •  

    Tags for this Thread

    Posting Permissions

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