ZeroSuf3r
ZeroSuf3r

Reputation: 2001

javascript passing variables via url

Well, question maybe doesn't correct, but I give a shoot.

My script:

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u);void(o)" onclick="return false">OMG, testing</a>

In real, without javascript url look like:

http://localhost/url=google.com

In here wanna add this: &format=txt

So, the correct url then would be:

http://localhost/url=google.com&format=txt

Upvotes: 0

Views: 1347

Answers (4)

Kunal Vashist
Kunal Vashist

Reputation: 2471

This will do it ,, you have to do same as you did for the localhost

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>

Upvotes: 1

MattP
MattP

Reputation: 2863

Just add it to the link using +, unless I misunderstood the question.

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>

Assumes txt is a variable, otherwise put it all in the quotes.

Upvotes: 1

Vikram
Vikram

Reputation: 8333

is this what you want:

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format=txt');void(o)" onclick="return false">OMG, testing</a>

Upvotes: 1

GregM
GregM

Reputation: 2654

like that :

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u + '&format=txt');void(o)" onclick="return false">OMG, testing</a>

You only have to add the text to the string of your url

Upvotes: 0

Related Questions