Skip to content

How to detect if mobile browser? #3183

Answered by hajimehoshi
esotericpig asked this question in Q&A
Discussion options

You must be logged in to vote
var isMobile = false

func init() {
	ua := js.Global().Get("navigator").Get("userAgent").String()
	isMobile = strings.Contains(ua, "Android") || strings.Contains(ua, "iPhone") || strings.Contains(ua, "iPad") || strings.Contains(ua, "iPod")
}

This should work in 99.99% cases.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@esotericpig
Comment options

Answer selected by esotericpig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants