Appending to a URL

P

Phat G5 (G3)

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
 
P

Pete

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='&';
}
 
E

Erwin Moller

Phat said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top