Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return to home page using javascript?

Tags:

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??

like image 368
Mud Hut Avatar asked Oct 31 '12 13:10

Mud Hut


2 Answers

Add .href:

function gohome()
{
window.location.href="../index.html"
}
like image 182
Andrea Ligios Avatar answered Sep 29 '22 18:09

Andrea Ligios


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.

like image 22
Ian Overton Avatar answered Sep 29 '22 18:09

Ian Overton