I am working on my mobile website and I have this code on my pages:
<a href="javascript:history.go(-1)">
attached to my logo.
this code works fine on my pages but I want my index page to refresh when logo is clicked and not go back a page.
how can I do this?
thanks.
OK: PROBLEM SOLVED,
I JUST HAD TO ADD
<a href="PAGENAME.html">
TO EACH PAGE WITH THE TITLE OF THE CURRENT .html PAGE.
THANK YOU FOR ALL YOUR HELP.
I am working on my mobile website and I have this code on my pages:
<a href="javascript:history.go(-1)">
attached to my logo.
this code works fine on my pages but I want my index page to refresh when logo is clicked and not go back a page.
how can I do this?
thanks.
OK: PROBLEM SOLVED,
I JUST HAD TO ADD
<a href="PAGENAME.html">
TO EACH PAGE WITH THE TITLE OF THE CURRENT .html PAGE.
THANK YOU FOR ALL YOUR HELP.
Share Improve this question edited Oct 8, 2012 at 14:43 Kev Hopwood asked Oct 8, 2012 at 13:57 Kev HopwoodKev Hopwood 1491 gold badge4 silver badges15 bronze badges 7- If i get your problem : When your on the home page, it should refresh the page right ? When your on another page, it shoud redirect you the the home page ? – Laurent Brieu Commented Oct 8, 2012 at 14:00
- hi Laurent Brieu, that is exactly right. – Kev Hopwood Commented Oct 8, 2012 at 14:22
- Ok so why don't you do : <a href="/index.php"> (replace index.php by your home page file name – Laurent Brieu Commented Oct 8, 2012 at 14:23
- hi Laurent Brieu, this is the simple way of doing this but it does not sort out my problem listed below. thanks. – Kev Hopwood Commented Oct 8, 2012 at 14:28
- Meaning home page refreshing ? – Laurent Brieu Commented Oct 8, 2012 at 14:29
4 Answers
Reset to default 3Use a relative url to redirect all clicks on the logo to the index page.
<a href="/"><img src="logo.png"></a>
You can check the location.href property to identify whether its in index or any other page and then decide whether to go back or refresh.
if(window.location.href.indexOf('index.') > -1)
window.location.reload();
else
history.go(-1);
For anyone stumbling on this, a more dynamic solution that doesn't require putting the current page url as the href on every page you can add a link like so:
<a href"JavaScript: location.reload(true);">refresh</a>
or as a button
<button onclick="location.reload(true);">Refresh</button>
or as input:
<input type="button" onClick="location.reload(true);" VALUE="Refresh">
Alternative javascript that would work in slightly different ways are:
javascript:history.go(0)
location.reload()
location.replace(location.pathname)
Using jquery would be -
$('#something').click(function() {
location.reload();
});
but seems unecessary
You get the idea. Hope that's helpful for someone else.
I found out using "./" works best for me