Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect page on button click event

Tags:

javascript

I am using a button on my form. How do I link to another web page/file when clicking on that link? Here is the code I tried, but does not work.

<button class="btn" data-bind="click: function() { document.location.href=$(this).attr('RiskAssessmentMain.aspx'); }">back</button>
like image 877
David Van Staden Avatar asked Feb 08 '13 06:02

David Van Staden


3 Answers

set the url you want to go in <form> action attribute. then use a submit instead of button.
Here is an example.:

 <form action="http://google.com">   
    <input type="submit" value="Google">
 </form>
like image 155
ѕтƒ Avatar answered Sep 29 '22 09:09

ѕтƒ


<input type='button'value='back' class="btn" onclick="document.location.href='RiskAssessmentMain.aspx';"/>

Try it: http://jsfiddle.net/wzy4B/

like image 43
Ahmet Kakıcı Avatar answered Sep 29 '22 09:09

Ahmet Kakıcı


You Can try this one

<script>
      function open_win() {
           window.open("http://www.google.com")
      }
</script>

Or you can also Do it like this

<script>
       function openWin() {
            myWindow=window.open('','','width=200,height=100');
            myWindow.document.write("<p>This is 'myWindow'</p>");
            myWindow.focus();
       }
</script>

<input type="button" value="Open window" onclick="openWin()" />
like image 30
ScoRpion Avatar answered Sep 29 '22 11:09

ScoRpion