onclick() function - how to link to page?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
rrn
Forum Commoner
Posts: 46
Joined: Wed Apr 15, 2009 7:54 am

onclick() function - how to link to page?

Post by rrn »

this is my html page..

Code: Select all

 
<html>
<head>
<script type="text/javascript" language="JavaScript">
function general_formats()
{
window.open('http://www.test.com/general_formats.php');
}
</script>
</head>
<body>
<a href="general_formats.php"><onclick="general_formats(); return false">General Formats</a>
</body>
</html>
When i click ' General Formats ' , a window is opened , i dont need that .
What i need is , when i click the link , it should direct to general_fomats.php..

please help me to solve it . .any help will be appreciated .
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: onclick() function - how to link to page?

Post by lshaw »

Change the line

Code: Select all

 
window.open('http://etc.com');
 
to

Code: Select all

 
window.location='http://etc.com';
 
That is untested but I am sure you get the idea :D

window.open will always open a new window (depending on the users browser settings :D )
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: onclick() function - how to link to page?

Post by kaszu »

it should be 'document', not 'window'

Code: Select all

document.location = 'http://etc.com';
rrn
Forum Commoner
Posts: 46
Joined: Wed Apr 15, 2009 7:54 am

Re: onclick() function - how to link to page?

Post by rrn »

window.location = ""
worked ...
Thank you guys.......
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Re: onclick() function - how to link to page?

Post by xjake88x »

I always use

Code: Select all

location.href='http://....';
. Old school?
Post Reply