Detecting Mobile browser and orientation - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: Detecting Mobile browser and orientation (/thread-908.html) |
Detecting Mobile browser and orientation - lfeliz - 01-17-2019 Planning on set of mobile friendly screens for my app. Need to detect mobile phones and tablets. How to detect phone based browsers so I can show mobile phone login ? Tablets are usually fine for full app in landscape. Would be nice to be able to alert user to rotate into landscape. I probably should have checked to see if there is a demo for this ..... Cheers! RE: Detecting Mobile browser and orientation - ShaneStump - 01-17-2019 Howdy Lou! In the ServerController, use the OnBrwoserCheck event. In the event, you will see a parameter of TBrowser. The TBrowser has an IsMobile property. Hope this helps. All the best, Shane RE: Detecting Mobile browser and orientation - lfeliz - 01-18-2019 (01-17-2019, 10:16 PM)ShaneStump Wrote: Howdy Lou!Thank you! That will get me going for a while until I need to detect landscape view, though I am only utilizing mobile right now as a way to lookup contacts and provide a summary of transactions etc... Eventually I will need a proper app, but that is for now a few years out. RE: Detecting Mobile browser and orientation - Сергей Александрович - 05-21-2021 Something is not working... Always defines as stationary. Look, I probably wrote something wrong... ServerController: public { Public declarations } mMobile : Boolean; end; ... procedure TIWServerController.IWServerControllerBaseBrowserCheck( aSession: TIWApplication; var rBrowser: TBrowser); begin if rBrowser.IsMobile then mMobile := true else mMobile := false; end; procedure TfmVmMain.IWAppFormShow(Sender: TObject); var begin if TIWServerController(WebApplication).mMobile then begin lblbUser.Caption := 'Mobile'; end else begin lblbUser.Caption := 'Stationary'; end; end; Always defines as Stationary RE: Detecting Mobile browser and orientation - DanBarclay - 05-21-2021 Try WebApplication.Browser.isMobile I'm not sure which is more reliable but that's what I've used for observation. I don't have behavior dependent on it but believe it would work fine. Dan RE: Detecting Mobile browser and orientation - Kristy - 05-21-2021 aSession.mMobile ? Its should be a variable of Usersession unit. RE: Detecting Mobile browser and orientation - raulevm - 05-22-2021 (05-21-2021, 05:55 AM)Сергей Александрович Wrote: Something is not working... Always defines as stationary. Look, I probably wrote something wrong... This procedure shows different forms according to the connected device, it could serve you Code: procedure TIWServerController.IWServerControllerBaseGetMainForm( RE: Detecting Mobile browser and orientation - Сергей Александрович - 05-23-2021 Thank you! "WebApplication.Browser.IsMobile" - works ! RE: Detecting Mobile browser and orientation - larryhems - 06-21-2022 In most cases developers use agent detection. But User Agent detection is not a recommended technique for modern web apps. There is a JavaScript API built-in for detecting media. You can use JavaScript window.matchMedia() method to detect a mobile device based on the CSS media query. Quote:if (window.matchMedia("(max-width: 767px)").matches) You may also use navigator.userAgentData.mobile . Quote:const isMobile = navigator.userAgentData.mobile; Another approach would be a responsive media query. You could presume that a mobile phone has a screen size greater than x and less than y. For example: Quote:@media only screen and (min-width: 320px) and (max-width: 600px) {} |