Frage

In my backbone app, when I load it in IE 7 and type the url: http://mydomain.com/ - which loads the main view - IE7 adds a hash tag at the end: http://mydomain.com/#

Which is weird, because all the other browsers don't.

Any ideas why?

One more thing:

I hardcoded a html link to the main view:

<a href="#">main view</a>

Is it good practice in placing a hashtag? or should I put something else in the href?

Maybe: javascript:void(0)

War es hilfreich?

Lösung

'#' means you are landed to a home page. So it's not a big deal if you let it be like that. becoz backbone will always use '#' based routing in IE7.

Possibly you using the Backbone.Router class to handle routing in your app. Backbone handles it very nicely in IE7 for you. Take a look at backbone's navigate method for more detailed use of it.

Andere Tipps

Backbone does this because IE is the only browser you're using which doesn't support history.pushState.

Backbone checks for this under the hood, and if it loads in a browser which supports pushState, it will use that as a single-page router.

If backbone loads in a browser without such support, it looks for the only other way to modify browser history without reloading the page: hashchange.

Backbone adds the hash to the URL immediately so you know it's being used, as far as I know.

Placing a hashtag to jump to a specific location on a page is good practice. Using a hashtag without a following location is not. If you want a link which jumps to your main page just insert the full URL like http://mydomain.org/ and if you want to jump back to the top specify an anchor #top at the top of your page and use that instead of #. The use of javascript:void(0) is quite a controversial topic. Generally you should separate the javascript from the html.

As to give an answer to your main question: It doesn't hurt to have the # in the URL as long as you are not using any custom logic for dealing with anchors. If you clicked a # link in your document it will redirect you to the top of the page. So if you reload the page completely you will be at the top anyway so it does not hurt if IE decides to add a hashtag.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top