12

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.

2
  • 7
    What's the point of using javascript to do this? <a href="/">Home page</a> is much, much simpler. Sep 24, 2012 at 12:32
  • i cant remove old code as some condition is coming in every case Sep 24, 2012 at 12:38

6 Answers 6

27

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

   function GoToHomePage()
  {
    window.location = '/';   
  }
0
5

Try this:

window.location = '/';

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

1
  • thnx for answer :-) and for explanation as well Sep 24, 2012 at 12:36
0

It looks like you need

window.location = '/default.aspx';

or

window.location = '/';

(not sure of your goal)

The '/' means "the root of the domain".

0

Add / before default.aspx and it should take you to home page

function GoToHomePage()
{
    window.location = '/default.aspx';   
}
2
  • its not working its redirecting to www.testtest.com/default.aspx and i want redirect to www.testtest.com Sep 24, 2012 at 12:31
  • Then change it to window.location = '/'; Sep 24, 2012 at 12:32
0

I would strongly recommend to use href instead of onclick due to various obvious reasons:

<a href="/">Home page</a>
0

It's working for me, as suggested by @Olly Hodgson:

<a href="/">Home page</a>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.