I'm looking to have it so that when a user loads our page it checks to see if they're on a mobile device and then it'll redirect them to a mobile version of our site, but keep the original hash tag from the link they followed. I've tried setting the new location with the hash tag in javascript and it works in Chrome but doesn't work in Safari. I've read that this is just something Safari does. Is there any work around to this?
In order to help Googlebot discover the location of your site's mobile pages, Google recommends websites must should: Add a rel="alternate" tag on the desktop page which points to the corresponding mobile URL. Add a rel="canonical" tag on the mobile page that points to the corresponding desktop URL.
In a URL, a hash mark, number sign, or pound sign ( # ) points a browser to a specific spot in a page or website. It is used to separate the URI of an object from a fragment identifier. When you use a URL with a # , it doesn't always go to the correct part of the page or website.
A hash sign (#) in a URL is referred to as a fragment. Historically, URL fragments have been used to automatically set the browser's scroll position to a predefined location in the web page. In that sense, if a URL refers to a document, then the fragment refers to a specific subsection of that document.
We actually just got a very similar bug report from our customers.
For us the scenario involved a hashtag in the form of #quicklogin/abc123
and only appeared when viewing the site in Safari. This was part of the initial URL that the client would load and it would present them with an alternate login screen. When going directly to the URL in Safari, the browser removed the entire tag and ignored it.
When we changed this to something like #quicklogin/test
(or any other hash containing only alpha characters) it worked fine. It also worked fine when loading the site and then manually applying the hash tag in two separate steps.
So our conclusion is that there may be something wrong with hashtags containing numeric values in Safari.
You have to do this either by redirecting with javascript (because javascript can read the hash value) or by conditionally returning different html based on the user agent.
Browsers are supposed to preserve the hash fragment through a 302, but often don't (see 3 year old webkit bug below) and otherwise hash fragments are not sent to the server so they can't be dealt with manually.
https://bugs.webkit.org/show_bug.cgi?id=24175
You should escape '#' symbol and everything would be OK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With