Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Javascript Javascriptexamples JavaScript Open URL

Related Tutorials


Share on Google+Share on Google+

JavaScript Open URL

This page discusses - JavaScript Open URL

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:

<script type="text/javascript">
function openURL(){
var urlToOpen = document.forms[0].url.value;
window.location = urlToOpen;
return false;
<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">

Output will be displayed as:

Enter any URL you want to open:

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

Download Source Code:



If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: JavaScript Open URL  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image