I have a php code here and I would like to create a "back" href to get me back to where I was before. Here\'s what I have:
<a href="javascript:history.back(1)">Back</a>
this one (by Eiko) is perfect, use css to make a button of <a>
...
eg you can use this css class in <a>
as `
<a class=".back_button" href="javascript:history.back(1)">Back</a>`
.back_button {
display:block;
width:100px;
height:30px;
text-align:center;
background-color:yellow;
border:1px solid #000000;
}
If you want to do it (what I think you are trying right now) then replace this line
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>
with this
<button type="button" onclick="history.back();">Back</button>
If you don't want to rely on JavaScript then you could get the HTTP_REFERER
variable an then provide it in a link like this:
<a href="<?php echo $_SERVER['HTTP_REFERER'] ?>">Back</a>
<button onclick="history.go(-1);">Back </button>
In my application,above javascript function didnt work,because i had many procrosses inside one page.so following code worked for me hope it helps you guys.
function redirection()
{
<?php $send=$_SERVER['HTTP_REFERER'];?>
var redirect_to="<?php echo $send;?>";
window.location = redirect_to;
}
<input type="submit" <a href="#" onclick="history.back();">"Back"</a>
Is invalid HTML due to the unclosed input
element.
<a href="#" onclick="history.back(1);">"Back"</a>
is enough
You need to tell the browser you are using javascript:
<a href="javascript:history.back(1)">Back</a>
Also, your input element seems out of place in your code.