Hugh Chalmers Hugh Chalmers - 1 month ago 9
CSS Question

How to block PCs from being able to access a webpage

I have the following code blocking phones.

if {
/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i
.test(navigator.userAgent)) {
window.location = "www.zentriamc.com/teachers/error.html"
}


How would I use this code (or different code) on another webpage, to block computers (not strictly PCs. Just every device NOT listed above)?

Answer

The else should work just fine...

if {
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i
        .test(navigator.userAgent)) {
} else {
        window.location = "somepage.html"
}
Comments