Forum Moderators: open
Just a quick question here.
Like a fool I presumed my website that works in Internet Explorer would also work in Firefox (3.0.5 to be precise). I have been testing it in Firefox and everything works except my 'Back' links.
When I click my 'Back to Gallery' links, in Firefox it just reloads the page I am on. It works fine in IE6. Here is my code:
<a href="#" onClick="history.go(-1);return true;" class="mtn">Back
to Gallery</a>
Is there anything wrong with what I am doing there? It's just standard code as far as I am aware.
Thanks
Mike
:-)
'Glad' cos it might give you time to reconsider you approach and NOT try to control the behaviour of your visitors' browsers
Mastery, Mystery and Misery - Jakob Nielsen [webmasterworld.com]
ETA
I found that thread by searching for the phrase
"break the back button" neilsen
[edited by: eelixduppy at 8:19 pm (utc) on Dec. 18, 2008]
[edit reason] fixed link [/edit]
In recent years, we've seen both users and browser makers 'push back' because of abuses such as sites disabling the Back button, throwing pop-ups on window open, page load, and mouse events, replacing the browser status line, etc. Firefox is a little out in front on this, and now prohibits many JavaScript 'tricks' that used to work.
By "tricks," I mean functions and features that were somewhat useful if used for good, but very, very bad if used with malicious intent.
So, the un-requested pop-up is now dead, and site navigation is to be done with either on-page links or the browser's navigation buttons, as it was before JavaScript was supported by browsers. If you cannot get the effect you need by document.write modifying the links on each image page, then there is likely a server-side solution to your problem.
Jim
Far from trying to control the behaviour of my visitors' browsers I simply included that navigation option as a further choice. I thought it must be popular amongst users as it certainly appears frequently throughout the internet.
I always use my browser's Back button when I am browsing, so if these 'back' links are troublesome as well as unpopular I'll remove them.
Thanks again
Mike
:-)
what bout just plain ol "back to home page"I think that the term 'back' is inappropriate here; many (if not most) visitors 'come in through a side door' (ie if they have never (yet) been to the 'home page', its nonsensical to invite them to go 'back' there)
or "back to previous?"All (?) relevant UAs (e.g browsers, not printers) have a back button already... why reinvent and then (for printers etc) remove the wheel?
<a href="#" onClick="history.go(-1);return true;" class="mtn">Back to Gallery</a>
This isn't a button breaker, but it does present some accessibility issues if JS is disabled. JD's on a good idea there, it's probably best to use document.write() to write this link to the browser so if JS is disabled it won't even be on the page.
But as to why it's not working, what you might not know is what you are doing here is Javascript, and you have to understand what return does.
In any Javascript function, the return value tells the browser whether or not to perform the natural action. For a form, it's submit; for an anchor, it's navigate to the href. Let me guess - when this link is say, in the middle of the page, it also scrolls back to the top, correct?
This is because you are returning true, which tells the browser to allow the link to navigate to the url in the href. Try
<a href="#" onClick="history.go(-1);return false;" class="mtn">Back to Gallery</a>
Further info: # is an identifier for an ID'd item on the page, and since it's a blank value, the default behavior is to scroll to the top. If you had
<a href="#bottom" onClick="history.go(-1);return true;" class="mtn">Back to Gallery</a>
and at the bottom of your page,
<p id="bottom">Bottom</p>
It would find that element and navigate to it.
P.S., you had me wondering so I just tested this in FF. Of course, you need a page to go BACK to, so navigate to something first before opening the page with this link.