Open In App

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:



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() {
                window.open("https://www.geeksforgeeks.org", "_top");
            }
        </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:


Article Tags :