You can use JavaScript to navigate the browser to a URL by setting the window.location.href
property to the desired URL. Here's an example:
javascript
// Define the URL you want to navigate to
var url = "https://www.example.com";
// Navigate to the URL
window.location.href = url;
In this example:
We define the URL we want to navigate to and store it in the
url
variable.We use
window.location.href
to set the browser's location to the specified URL by assigning theurl
variable to it.
When you run this JavaScript code in a web page, the browser will navigate to the specified URL (in this case, "https://www.example.com").
Comments
Post a Comment