Forum Moderators: open

Message Too Old, No Replies

Build URL string?

How to build a URL string in javascript?

         

RayF

10:46 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



I want to build a URL string javascript, but I'm not sure how to do it.
Basically, I want to add parameters to the URL string, separated by &.

It would look something like this:

<A HREF="http://www.blah.com/" onClick="build_url()">build url</A>

<script language="javascript">
function build_url() {
// add parameters to URL string
}
</script>

For example, I want to add several parameters to the URL string, like:

param1=some_string1
param2=some_string2
param3=some_string3
param4=some_string4

all separated by &.

Bernard Marx

1:45 am on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where are the parameter names & values held - variables?

RayF

6:12 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Yes, they are all string variables. The full URL string would look like:
hhhp://www.blah.com&param1=value1&param2=value2&param3=value3&param4=value4

What I would like to know, can I access the anchor's HREF variable?
Does this have a member name? If so, what is it?
Or do I have to build an entirely new URL from scratch?

And I now notice that after I changed the link to use javascript, MSIE now tries
to block my link with a popup security warning? Is this unavoidable?

orion_rus

7:47 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Your url is a string. U can modify it as you want, but each variable and value should have constant syntax as u type before.
to build you url your function should be like this

<a href='somewhere' onclick=buildurl(this)>GOO</a> //this means what u send this object
function buildurl(newhref)
{newstring='somesite.com?onevariable=onevalue';
newhref.href=newstring;
}

that's all.
All you need is to make a string.
You can do it with javascript variables like
statevariable='good';
statevalue='yes';
{newstring='somesite.com?'+statevariable+'='+statevalue';
and you get somesite.com?good=yes
then change href to it
newhref.href=newstring;
all is simple)
good luck to you

orion_rus

7:48 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



it's avoidable just use
location.href=newstring;

RayF

8:51 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Nope, it doesn't help. I have to remove my javascript completely, or MSIE will
still block it. Well, that's no good.

"To help protect your security, Internet Explorer has restricted this file from showing active
content that could access your computer. Click here for options..."

orion_rus

8:53 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



May be just make lower security level of IE?

Bernard Marx

12:46 am on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"To help protect your security, Internet Explorer has restricted this file from showing active
content that could access your computer. Click here for options..."

- only happens on your PC, not online

[webmasterworld.com...]

RayF

3:46 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



Thanks, that was it. I'm testing this locally on my computer.

Had to add this at the top of my HTML page:
<!-- saved from url=(0014)about:internet -->

Worked perfectly after that.