JavaScript Open URL
In this section, you will learn how to open the url on the window.
As we know that window.location object that contains the current URL information. In the given code the document.forms[0].url.value gets the entered URL and used this object to open the entered URL. For this purpose, we have created a textbox to allow the user to enter any URL to open and click the button. As you click the button, the entered URL will get open.
Here is the code:
| <html> <script type="text/javascript"> function openURL(){ var urlToOpen = document.forms[0].url.value; window.location = urlToOpen; return false; } </script> <body bgcolor="lightBlue"> <form method="get" onsubmit="return openURL()"> Enter the URL to open: <input type="text" id="url"><br> <input type="submit" value="Submit"> </form> </body> </html> |
Output will be displayed as:
Enter any URL you want to open:

When you submit the button, the entered URL will get open:

Tutorials
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


