I am trying to do a very simple task here, I would like to be able to click a button on a page and have it take me to another page. I have tried window.location.href, and a bunch of other things and it does nothing. I have tried different platforms and different browsers, all with the same result.
I know that it can call a function but I just cannot get the new page to load. Also this is all in my local file system and both pages live at the same level (but I have also tried to load an external page like www.apple.com).
Any thoughts?
Thanks Patrick
Approach: We can use window. location property inside the script tag to forcefully load another page in Javascript. It is a reference to a Location object that is it represents the current location of the document. We can change the URL of a window by accessing it.
run:function() { var that = this; document. getElementById("watchButton"). addEventListener("click", function() { that. _handleWatch.
To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.
To link a submit button to another webpage using HTML Form Tags: Using the HTML Form's Action Attribute, we can link the submit button to a separate page in the HTML Form element. Here, declare/write the “Submit button” within HTML Form Tags and give the File Path inside the HTML form's action property.
Simple code to redirect page
<!-- html button designing and calling the event in javascript --> <input id="btntest" type="button" value="Check"         onclick="window.location.href = 'http://www.google.com'" /> 
                        Don't abuse form elements where <a> elements will suffice.
<style>     /* or put this in your stylesheet */      .button {         display: inline-block;         padding: 3px 5px;         border: 1px solid #000;         background: #eee;     }  </style>  <!-- instead of abusing a button or input element --> <a href="url" class="button">text</a> 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With