Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript load a page on button click

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

like image 909
Patrick Avatar asked Sep 10 '10 07:09

Patrick


People also ask

How do I load a page using Javascript?

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.

How do you click a button on Pageload?

run:function() { var that = this; document. getElementById("watchButton"). addEventListener("click", function() { that. _handleWatch.

How do I load an HTML page into a div?

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.

How do I move one HTML page to another button?

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.


2 Answers

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'" /> 
like image 137
Pranay Rana Avatar answered Sep 22 '22 04:09

Pranay Rana


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> 
like image 45
BGerrissen Avatar answered Sep 20 '22 04:09

BGerrissen