Appending to a URL

Discussion in 'Javascript' started by Phat G5 (G3), Jun 14, 2007.

  1. Phat G5 (G3)

    Phat G5 (G3) Guest

    I was thinking of writing a little function to help reduce the amount of
    code needed in a few places.

    function link(url)
    {
    return( url + '?-session_id=' + user.session_id );
    }


    Then I simply have a line like so:

    x.location = link('/clientdb/newclient.lasso');

    Now, here is the question... Say I have a parameter already after the .lasso
    like xxx.lasso?page=123
    What would be the best approach to determine that within the link function?
    Look for a ? and if it finds one to append with an & rather than a ?

    -S
    Phat G5 (G3), Jun 14, 2007
    #1
    1. Advertising

  2. Phat G5 (G3)

    Pete Guest


    > What would be the best approach to determine that within the link function?
    > Look for a ? and if it finds one to append with an & rather than a ?


    This should do the trick:

    var ch = '?'
    if (url.indexOf(ch)!=-1) {
    ch='&';
    }
    Pete, Jun 14, 2007
    #2
    1. Advertising

  3. Phat G5 (G3)

    Erwin Moller Guest

    Phat G5 (G3) wrote:

    > I was thinking of writing a little function to help reduce the amount of
    > code needed in a few places.
    >
    > function link(url)
    > {
    > return( url + '?-session_id=' + user.session_id );
    > }
    >
    >
    > Then I simply have a line like so:
    >
    > x.location = link('/clientdb/newclient.lasso');
    >
    > Now, here is the question... Say I have a parameter already after the
    > .lasso like xxx.lasso?page=123
    > What would be the best approach to determine that within the link
    > function? Look for a ? and if it finds one to append with an & rather than
    > a ?


    Yes.

    Regards,
    Erwin Moller

    >
    > -S
    Erwin Moller, Jun 14, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Cholakian

    Appending to XML

    Andrew Cholakian, Jul 17, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,043
    Andrew Cholakian
    Jul 17, 2003
  2. Jeff Cooper

    Netscape Appending .aspx to downloads

    Jeff Cooper, Oct 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    317
    Jeff Cooper
    Oct 21, 2003
  3. Jon paugh
    Replies:
    1
    Views:
    702
  4. =?Utf-8?B?U3JpZGhhcg==?=

    appending a unique id to the url

    =?Utf-8?B?U3JpZGhhcg==?=, Oct 26, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    455
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
    Oct 27, 2006
  5. Just D.
    Replies:
    0
    Views:
    416
    Just D.
    Aug 11, 2004
Loading...

Share This Page