|
-
Nov 12th, 2002, 07:53 AM
#1
Thread Starter
Addicted Member
Calling a javascript function in a "a href=" statement
Heya, Im a Javascript n00b, just curious as to why this script doesn't work , i know it's basic...
This is the function in the head section of a HTML file...
VB Code:
<script language="JavaScript">
<!--
Function callpic(picname)
{ var h = 480;
var w = 640;
var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
var fullpicname="http://users.bigpond.net.au/maniac/images/"+picname;
window.open('fullpicname', 'blank', 'width='+w+', height='+h+', top='+t+', left='+l);
}
//-->
</script>
And this is a link which I want to call the function ...
VB Code:
<a href="http://***.***.net.au/***.htm" onClick="callpic('game-nfs1.jpg');">Image 1</a>
any thoughts, opinions or ***'s appreciated
-
Nov 12th, 2002, 08:24 AM
#2
Frenzied Member
function should have a lowercase "F" at the start. Also if I understand what you are trying to do you may want to return false at the end of the onclick bit, so that the href won't be executed.
-
Nov 12th, 2002, 08:27 AM
#3
Retired VBF Adm1nistrator
This should work
Code:
<a href="http://***.***.net.au/***.htm" onClick="javascript:callpic('game-nfs1.jpg');">Image 1</a>
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 12th, 2002, 08:27 AM
#4
Thread Starter
Addicted Member
Yeh thats what I'm trying to do , thanks, but whats the syntax for returning false? sorry im just doing this by trial and error...
-
Nov 12th, 2002, 08:28 AM
#5
Retired VBF Adm1nistrator
for some reason VBF put a space between "java" and "script"...
there shouldn't be a space there
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 12th, 2002, 08:29 AM
#6
Thread Starter
Addicted Member
Ok thanks ppl already got it working :w00t: 
suuuuure VBF...
-
Nov 12th, 2002, 02:24 PM
#7
Frenzied Member
To return false you do this:
<a href="http://***.***.net.au/***.htm" onClick="callpic('game-nfs1.jpg'); return false;">Image 1</a>
or:
<script language="JavaScript">
<!--
function callpic(picname)
{ var h = 480;
var w = 640;
var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
var fullpicname="http://users.bigpond.net.au/maniac/images/"+picname;
window.open('fullpicname', 'blank', 'width='+w+', height='+h+', top='+t+', left='+l);
return false;
}
//-->
</script>
<a href="http://***.***.net.au/***.htm" onClick="return callpic('game-nfs1.jpg');">Image 1</a>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|