PennController for IBEX › Forums › Support › Restricting to desktop › Reply To: Restricting to desktop
July 7, 2020 at 5:37 pm
#5770
Jeremy
Keymaster
Hi,
There’s no bulletproof method to ensure that someone is using a desktop rather than a phone or a tablet, but there are good approximation methods.
One option is to check the width of the screen:
newTrial( newFunction( ()=>window.matchMedia("only screen and (max-width: 760px)").matches ) .test.is(true) .success( newText("<p>We're sorry but this experiment requires a wider resolution.</p>"+ "<p>Please do not use a modile device to take this experiment.</p>"+ "<p>If you are using a desktop browser, make sure to maximize this window.</p>") .print() , newButton().wait() ) )
Another solution is to use user agent sniffing:
newFunction( ()=>navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) ) .testNot.is(null)
Jeremy