Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's wrong with using 'javascript:history.go(-1)'?

came across some twitter banter about how terrible it is to use

javascript:history.go(-1)

of course without any hints as to why.

If it's so terrible, why? What's the alternative? (besides history.back(), which seems to do exact same thing). Is it a matter of cross browser compatibility?

For example, I've seen it used on an error page to let users try to "go back" using the above.

I've tried google, but an no avail, in regards to why it'd be so horrible to use. Any pointers/explanations would be appreciated.

Thanks.

like image 323
andryuha Avatar asked Feb 25 '11 03:02

andryuha


1 Answers

They may have been referring to use of the pseudo protocol javascript:, which generally means this is an anchor's href attribute, which is ugly. It is not a real link, and with JavaScript disabled, it'll do nothing whilst looking like a functional link. I think the only valid use for this protocol is for bookmarklets.

Also, as Russell Dias points out, it does exactly the same as the back button, so what is the point of having it? Should we have a reload button too that calls window.location.reload() ?

like image 138
alex Avatar answered Sep 22 '22 00:09

alex