I have in a variable (var lan= urlParam('language')
) the selected language.
I want to pass this language as parameter (without using PHP) in a url in an "a
" tag, like this:
<a href=".aspx?languageCode=lan">
but it doesn't work.
I am waiting for your answers. Thank you a lot.
I have in a variable (var lan= urlParam('language')
) the selected language.
I want to pass this language as parameter (without using PHP) in a url in an "a
" tag, like this:
<a href="http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=lan">
but it doesn't work.
I am waiting for your answers. Thank you a lot.
Share Improve this question edited Sep 14, 2011 at 13:45 Quasdunk 15.2k3 gold badges39 silver badges47 bronze badges asked Sep 14, 2011 at 13:36 AlekaAleka 111 gold badge1 silver badge2 bronze badges 1- You want to dynamically, using JavaScript, add a new GET parameter to every link that is on the page. Is that correct? – Jan Hančič Commented Sep 14, 2011 at 13:38
2 Answers
Reset to default 2Your url is inside a string, so it won't put the value of your variable, but just the string "lan".
Give an ID to your link, so you can take it and change its url with javascript.
<a id="foo" href="http://hotelsbined.sitewish.gr/HotelNameSearch.aspx">
Then, with JS
document.getElementById('foo').setAttribute('href', 'http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=' + lan);
If I understand correctly, you can just use document.write to print the link and add the variable as the language parameter.
<script type="text/javascript">document.write("<a href=\"http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=" + lan + "\">link description</a>");</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745453471a4628376.html
评论列表(0条)