JavaScript method location
In this section, you will learn the use of JavaScript location.href.
JavaScript provides several ways to display any other page in the current browser window using location property of the window object. One of them is location.href which redirects the user straightforward to the specified URL. In the given example, we have specified an URL "http://www.roseindia.net" to redirect the user to it.
Here is the code:
| <html> <h2>Use of property location.href</h2> <script language="JavaScript" type = "text/javascript"> function setLocation(){ location.href = "http://www.roseindia.net";; } </script> <button onclick="return setLocation();">Go To www.roseindia.net</button> </html> |
Output will be displayed as:
On clicking the you will move to www.roseindia.net:

Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


