Mud Hut
Mud Hut

Reputation: 645

How to return to home page using javascript?

i am a newbie to jscript. i have used this code in javascript to return to home page

function gohome()
{
window.location="../index.html"
}

and i am calling that function in this code

'<a accesskey="h" id="home" href="javascript:gohome();">Home<\/a>' +

there will be link on a page when it is clicked it will call gohome() function. but same link is appearing on the index page.when clicked it is showing page not found.

How to make this link hide in index.html page?

Can anyone help me??

Upvotes: 5

Views: 20466

Answers (2)

Ian Overton
Ian Overton

Reputation: 1060

I don't think you need a javascript function to do go home you can just do this:

<a accesskey="h" id="home" href="../index.html">Home<\/a>

if you don't want it to show on the home page though you can do something like this assuming the home page is example.com/index.html

if(window.location.pathname=="/index.html"){
 document.getElementById('home').style.display = 'none';
}

Not in the function, but just called sometime after the link in the source code or in the head.

Upvotes: 5

Andrea Ligios
Andrea Ligios

Reputation: 50203

Add .href:

function gohome()
{
window.location.href="../index.html"
}

Upvotes: 7

Related Questions