Reputation: 37771
Is there a way to detect, using javascript or a js library, if my website has been opened inside a QR code reader app?
The reason I'm asking is because I'm using orientation
detection, which doesn't work when the webpage is viewed through some of the QR code apps. (The ones that are forced to portrait mode in the app.)
So I'd like to just pop up a message that says "This site won't work properly unless you open the link in Safari", or something like that. (Because I guess there's no way for me to force it to open in Safari through JS?)
Upvotes: 1
Views: 1942
Reputation: 14792
You could try to get the user agent string from the navigator object in js:
navigator.userAgent
Maybe the QR-App identifies itself there, but as everything on the phones is opened with the default webbrowser there's only a slim chance that might work.
Maybe you could create a fallback for your orientation by calculating with the width and height of the whole page. That way you could detect a difference between reported orientation from the device and real device orientation. You could use that difference as a switch to show the message.
Upvotes: 7