-2

I have tried to prevent users from accessing my mobile website from desktop browsers by determining user-agent and screen-size however by both ways they can still access my mobile site either by changing the user-agent (Desktop Chrome > More Tools > Developer Tools > Network > Network Conditions) or by resizing the screen. Is there any somewhat fool-proof (or somewhat difficult to crack) way to prevent users from access my mobile website from desktop browsers other than user-agent and screen-size?

P.S: The reason users do this is because there are no ads on my videos yet on mobile as I am promoting my web-app through ad-free experience, but many desktop users are misusing the feature.

  • _"Is there any somewhat fool-proof way"_ No. – Alex Howansky Apr 18 '17 at 18:54
  • 1
    "many desktop users are misusing the feature." No, they're not. Putting stuff on the web means browsing it from any device. The web's not built to be restrictive in this way. – Matt S Apr 18 '17 at 18:56
  • 1
    I understand, Alex. But looking for options to prevent other than determining user-agent and screen-size. – sunny43 Apr 18 '17 at 18:57
  • There are also ad-blockers. I think the user wants to decide himself, how he uses your page. You can ask for donations, to turn off the ad-blocker or make premium accounts without ads. – maraca Apr 18 '17 at 18:57
  • Ad-blockers doesn't block my video ads, at-least for now. – sunny43 Apr 18 '17 at 18:59
  • You could try `navigator.platform` (javascript) but someone could spoof that too (not easily though). – Tom Udding Apr 18 '17 at 19:00
  • Tom, Can you please explain a bit? A sample code? – sunny43 Apr 18 '17 at 19:01
  • "at-least for now" Give it a few minutes. – Ignacio Vazquez-Abrams Apr 18 '17 at 19:06
  • Well, `navigator.platform` returns machine type for which the browser was compiled (the platform on which the browser is executing), e.g. MacIntel or Windows. Since this is also send by the browser (like the UA) you must not rely on this sole feature (there are some ways to spoof it). I have found [this (probably not complete) list](http://stackoverflow.com/a/19883965/5914775) with some more information. And [this](http://stackoverflow.com/a/11752084/5914775) is also a great answer to this (your, almost the same) question. – Tom Udding Apr 18 '17 at 19:10
  • No. Because you have to rely on user-supplied information to make the determination, and you can clearly see how that doesn't work. – Sammitch Apr 18 '17 at 19:19
  • @TomUdding Thanks, navigator.platform does help for now :) Thanks for links to more detailed and relevant answers. – sunny43 Apr 19 '17 at 11:38

1 Answers1

0

What i do, which seems to work well, is to check the orientation of the device and make them turn there device sideways. most desktop users cant figure out how to game this and it does the job most of the time.

I also check for some mobile features that generally are not found in desktop browser including checking for:

  1. the dppx
  2. orientation
  3. handheld query
  4. test for ontouch events

(if ('ontouchstart' in window) {...})

  1. force user to change orientation, check for change, and redirect if after certain time change hasn't been registered for orientation change

//function doOnOrientationChange() {/////

function doOnOrientationChange() {
switch(window.orientation) {  
  case -90 || 90:
    alert('landscape');
    break; 
  default:
    alert('portrait');
    break; 
}
}

window.addEventListener('orientationchange', doOnOrientationChange);

// Initial execution if needed
doOnOrientationChange();

Using these ideas combined with browser checking/sniffing, touch events, screen size etc will get you about as close as you can get to locking users into a desktop version of the site.

ATechGuy
  • 1,240
  • 8
  • 13