Open a link without clicking on it using JavaScript
Problem Statement: How to open a link without clicking on it using JavaScript?
Solution: The link will be open when the mouse moves over the text. It returns a newly created window, or NULL if the call gets failed.
Syntax:
window.open( URL, name, Specs )
Parameters: This function accepts three parameters as mentioned above and described below:
- URL: It is optional parameter. It is used to specify the URL of the web page which need to open. If URL is not specified then a new Window is open.
- Name: It is an optional parameter which is used to specify the target attribute.
- _blank: The URL is loaded into the new window. It is optional.
- _top: The URL replaces the current page.
- Specs: It is an optional parameter. It is a comma-separated list of items, no whitespace.
- Height: It represents the height of window in the pixel.
- Width- It represents the width of window in the pixel.
Note: Allow Pop-up of Web Browser.
Program 1: URL is loaded into the new window.
<!DOCTYPE html> <html> <head> <title>Javascript open link without click</title> <style> .gfg { text-align:center; font-size:40px; font-weight:bold; color:green; } </style> <script> function myFunction() { window.open("https://www.geeksforgeeks.org"); } </script> </head> <body> <div class = "gfg" onmouseover = "myFunction()"> GeeksforGeeks </div> </body> </html> |
Output:
Program 2: URL is loaded into the current Window.
<!DOCTYPE html> <html> <head> <title>Javascript open link without click</title> <style> .gfg { text-align:center; font-size:40px; font-weight:bold; color:green; } </style> <script> function myFunction() { } </script> </head> <body> <div class = "gfg" onmouseover = "myFunction()"> GeeksforGeeks </div> </body> </html> |
Output:

Program 3: URL is loaded into the new window of specific size.
<!DOCTYPE html> <html> <head> <title>Javascript open link without click</title> <style> .gfg { text-align:center; font-size:40px; font-weight:bold; color:green; } </style> <script> function myFunction() { window.open('https://www.geeksforgeeks.org', ' ', 'width=500, height=300'); } </script> </head> <body> <div class = "gfg" onmouseover = "myFunction()"> GeeksforGeeks </div> </body> </html> |
Output:

Recommended Posts:
- How to display confirmation dialog when clicking an <a> link using JavaScript / jQuery ?
- Sound generation on clicking the button using JavaScript
- How to change the background color after clicking the button in JavaScript ?
- How to trigger a file download when clicking an HTML button or JavaScript?
- How to Open URL in New Tab using JavaScript ?
- How to create a link in JavaScript ?
- How to replace plain URL with link using JavaScript ?
- Open all persons solution links from submission page using JavaScript
- Javascript | Window Open() & Window Close Method
- How to avoid dropdown menu to close menu items on clicking inside ?
- What does '<?=' short open tag mean in PHP ?
- What is OAuth (Open Authorization) ?
- AngularJS | ng-open Directive
- How to open a PDF files in web browser using PHP?
- HTML | DOM open() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



