質問

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?

役に立ちましたか?

解決

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>

他のヒント

Since you are using it for a mobile app, it's best to use pure JavaScript:

function OpenWin(){
  window.open("url");
}
window.onclick = OpenWin();

Just add an event listener to the body so that the URL opens when they click anywhere:

document.getElementsByTagName("body")[0].addEventListener("click", function(){
  window.open(url);
});

You can try like this codes.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> 
<html><head> 
<title>body onclick test</title> 
</head> 
<body onclick="window.location.href='newpage.html';"> 
<h1>onclick test</h1> 
<p>test</p> 
</body> 
</html>

This will work, you do not need the div tag but I think it looks better and would help add control for styling later. One issue you might run into is text styling which will just need a CSS styling for the text color and decoration to get rid of unwanted underlines.

<html>
    <body>
        <a href='link.com'>
            <div>
                All content
            </div>
        </a>
    </body>
</html>

Try this for tab event-

 document.onkeydown = function(e){
    if (e.keyCode == 9) {
        alert("");
       window.open("www.google.com");

  }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top