Onclick Open URL in same window JS | Example Code

  • by

There are many ways to open an URL in the same window using HTML or JavaScript. Some methods are:-

window.open("eyehunts.com", "_self")

window.location.href = "eyehunts.com"


Note: use proper HTTP URL to open a website

If you want to do this in HTML:

<a href = "eyehunts.com" target = "_self"> </a>

Onclick Open URL in same window Examples:

HTML example code:

Used window.open for opening link in JavaScript

The second parameter of window.open() is a string representing the name of the target window.


		window.open("https://eyehunts.com/", "_self")



JavaScript Onclick Open URL in same window

Using HTML anchor Tag

You have to click on the link to open an URL in the same tab.

	<a href = "https://eyehunts.com/" target = "_self"> Click Here </a>


_self – URL replaces the current page.

Do comment if you have any doubts or suggestions on this JS URL topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.