Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick page go to homepage without any absolute path

I want to click on link and I want to go to the page on home page by it self

<a onclick="javascript:GoToHomePage()" href="javascript:void(0)">Home page</a>

function is

function GoToHomePage()
{
    window.location = 'default.aspx';   
}

but i want the url of page www.testtest.com instead of www.testtest.com/default.aspx

I can't even give the absolute path like www.testtest.com as it's a portal and same page coming in few more portals.

like image 732
supersaiyan Avatar asked Sep 24 '12 12:09

supersaiyan


People also ask

How do I go to homepage in HTML?

Try this: window. location = '/'; Executing this code will send your visitor directly to the root of your website.

What is alternative for onclick?

You should use addEventListener() instead."

Why is Onclick undefined?

The "Cannot read property 'click' of undefined" error occurs when trying to call the click() method on an undefined value. To solve the error, run the JS script after the DOM elements are available and make sure you only call the method on valid DOM elements.

How do you add a hyperlink to Onclick?

onClick = function () { alert(1); // To test the click }; var link = $("<a>"+ $("#attachmentName"). text() +"</a>"); $("#attachmentName"). html($(link); link.


2 Answers

Try this:

window.location = '/';

Executing this code will send your visitor directly to the root of your website.

like image 172
Erwin Avatar answered Oct 18 '22 04:10

Erwin


following code will take you to '//www.testtest.com/'

   function GoToHomePage()
  {
    window.location = '/';   
  }
like image 26
Anoop Avatar answered Oct 18 '22 04:10

Anoop