Open In App

How to Open a Link Without Clicking on it using JavaScript?

Last Updated : 03 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

To open a link without clicking on it we can use the onmouseover method of JavaScript. The link will 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 )

Note: Allow Pop-up of Web Browser.

Example 1: URL is loaded into the new window.

HTML
<!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>

</head>

<body>
    <div class="gfg" onmouseover="myFunction()">
        GeeksforGeeks
    </div>
    <script>
        function myFunction() {
            window.open("https://www.geeksforgeeks.org");
        }
    </script>
</body>

</html>

Output:

Example 2: URL is loaded into the current Window.

HTML
<!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>

</head>

<body>
    <div class="gfg" onmouseover="myFunction()">
        GeeksforGeeks
    </div>
    <script>
        function myFunction() {
            window.open("https://www.geeksforgeeks.org", "_top");
        }
    </script>
</body>

</html>

Output:

Example 3: URL is loaded into the new window of specific size.

HTML
<!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>

</head>

<body>
    <div class="gfg" onmouseover="myFunction()">
        GeeksforGeeks
    </div>

    <script>
        function myFunction() {
            window.open('https://www.geeksforgeeks.org',
                ' ', 'width=500, height=300');
        }
    </script>
</body>

</html>

Output:


Next Article

Similar Reads