View Full Version : Javascript variables as links
Abaddon
08-18-2004, 04:26 PM
I am trying to get a website that has a dynamic navigation where when you click a button, it adds or subtracts from a variable value. Example:
If you click the 'back button' on page 24, it subracts 1 from the value of variable 'pagenumber' and adds ".html" to the end of the variable to where it comes out like this:
23.html
Is there a way I can insert that value using Javascript or HTML into a link? Like, could I type something like:
<a href=javascript:var pagenumber>something goes here</a>
And get the result I am looking for? :confused:
Abaddon
08-18-2004, 10:19 PM
I want it to be like this:
<html>
<title>CodeAve.com(JavaScript:
Passing Variables via Links)</title>
<script language="JavaScript">
<!--
function variable_in_link(varible_value)
// function variable_in_link will assign the first variable
// passed to it as variable_value
{
new_win = window.open('http://www.'+varible_value+'.com','', 'width=640,height=400,left=10,top=10')
}
// -->
</script>
<body bgcolor="#FFFFFF">
<a href="javascript:variable_in_link('yahoo')">Yahoo</a>
<br>
<a href="javascript:variable_in_link('aol')">AOL</a>
<br>
<a href="javascript:variable_in_link('lycos')">Lycos</a>
<br>
<a href="javascript:variable_in_link('altavista')">AltaVista</a>
<!-- The variable value being passed to the JavaScript function
is encased in parenthesis and single-quoted -->
</body>
</html>
Only I don't want it to open in a new window.
corey84
08-18-2004, 10:30 PM
try replacing window.open with location.href
Abaddon
08-19-2004, 12:56 AM
I'm sorry but could you show me the code? I have never made an actual link in javascript before. :D
corey84
08-23-2004, 01:40 AM
instead of
new_win = window.open('http://www.'+varible_value+'.com','', 'width=640,height=400,left=10,top=10')
try
new_win = location.href('http://www.'+varible_value+'.com','', 'width=640,height=400,left=10,top=10')
Abaddon
08-24-2004, 06:45 PM
Thanks alot! :D
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.