简体   繁体   中英

Why is linkedIn adding a pound exclamation mark (hashbang) to my URL?

When sharing a link I've noticed that linkedIn appends a '#!' to the end of the URL after redirecting. This is breaking my Backbone.js single-page app since we use pushstate in the URL, and so the '!' is interpreted as a Backbone.js route.

Here is an example link (not my site). It will take you to: http://blog.mindresearch.net/blog/bid/336633/The-Connection-Between-Math-and-Neuroscience# !

I know I can filter this on the server-side, or deal with it on the client-side in numerous ways, but it just seems strange, and I saw no posts online about this topic, so thought I'd post a question asking what it is, and whether there is a way to get rid of it?

Of course, I'll also email LinkedIn support, but thought this could be useful to anyone else running into the same problem.

AFAIK anything after the hash is not sent to the server; I use a simple client-side script to redirect those URLs. A naive redirect, but it works. I don't see any way of preventing it from occurring, unless LinkedIn and Facebook change their outgoing redirect policy.

<script>
  if( window.location.hash == '#!' ) {
    window.location.href = 'http://domain.tld/';
  }
</script>

Sure it only works for JavaScript enabled clients, but then again in my experience those hashbang URLs only break those clients in the first place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM