How do I double click on some html element and that I'm directed to a new page with javascript?

2

This helps me but what interests me is linking to a page in this case a form, but I would like to know how it can be done in javascript within the dblClick function

<script type="text/javascript">
  $(document).ready(function(){
     $("tr").dblclick(function(){
         alert("Se ha hecho doble click");
     });
  });
</script>
    
asked by Jonathan Rodriguez Hernandez 07.08.2018 в 07:06
source

1 answer

1

I leave the example you want to perform with JavaScript pure, since being a very simple task I do not see the need to do it through JQuery

  

To be able to open the new page you want with pure JavaScript,   both for the JS or JQuery example use the method   window.open ('example.com') that will open a new browser tab   web you are using

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<button id="clickme">abrir otra página</button>
<script>
    let btn = document.querySelector("#clickme")

    btn.addEventListener("dblclick", function(){
      window.open("https://www.google.com.mx")
    })
</script>
</body>
</html>
  

The only thing I do is get the button by its ID and by a    handler indicated that when the dblclick event is executed and   finally through the "window" browser object I access the   open method and in the form of a text string I indicate the URL of the   web page that will open

If you still need it with JQuery here is the example

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<button id="clickme">abrir otra página</button>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script>
$(document).ready(function(){
      $("button").dblclick(function(){
        window.open("https://www.google.com.mx")
        console.log(1)
      })
})
</script>
</body>
</html>

Check the exercise from this link

link

    
answered by 07.08.2018 / 07:17
source