Reputation: 15
I am trying to use an image as a button to refresh pages on a website. The footer (a php include) is currently using this code to refresh each page:
<a href="javascript:void(0);" onClick="javascript: location.reload(true);" name="Reset page" title="Reset page"><img src="/images/refresh.png"></a>
which of course works. BUT I would like to improve it. Essentially, it would be something like this:
onClick="javascript: window.location.href='abcd.html';"
BUT I need it to work dynamically because I'm using php pages. So I was thinking this would work:
<a href="javascript:void(0);" onClick="javascript: window.location.href='<? php $_SERVER['REQUEST_URI'] ?>';" name="Reset page" title="Reset page"><img src="/images/refresh.png"></a>
But it doesn't work. Any ideas? I'm using <? php $_SERVER['REQUEST_URI'] ?>
wrong (obviously), so, any ideas for assistance? Thank you for any help!
Upvotes: 0
Views: 510
Reputation: 38645
Problem noticed is you have a space between <?
and php
in the following line:
<a href="javascript:void(0);" onClick="javascript: window.location.href='<? php $_SERVER['REQUEST_URI'] ?>';" name="Reset page" title="Reset page"><img src="/images/refresh.png"></a>
Also you want to echo out the value for $_SERVER['REQUEST_URI']
. You are just calling $_SERVER['REQUEST_URI']
. Also as @NickCoons pointed out when using the echo
construct you need to add a semi-colon i.e. echo $_SERVER['REQUEST_URI'];
.
Try the following:
<a href="javascript:void(0);" onClick="javascript: window.location.href='<?php echo $_SERVER['REQUEST_URI']; ?>';" name="Reset page" title="Reset page"><img src="/images/refresh.png"></a>
Upvotes: 2