Search code examples
htmlhyperlinkhref

HTML open link click anywhere


I'm a mobile programmer who never developed any webpage

I've created a blank HTML page and I want to open new link when the user click or tap anywhere.

Is it possible?


Solution

  • that's an interesting question with many solutions. I'll post two.

    Solution 1 - use a full width anchor tag

    <html>
        <head>
            <style>
                html, body { margin: 0; padding: 0; width: 100%; height: 100%; }
                a { display: block; width: 100%; height: 100%; }
            </style>
        </head>
        <body>
            <a href='#'></a>
        </body>
    </html>
    

    Solution 2 - use javascript, and add a click event on the body

    <html>
        <body onclick='window.location.href="http://google.com"'>
        </body>
    </html>