Option to disable isMobileDevice detection

111 views
Skip to first unread message

Kai Brümmer

unread,
Jan 7, 2015, 3:13:04 AM1/7/15
to pdfnet-w...@googlegroups.com
Dear all,

we use WebViewer in our application. At the moment we use a modified webviewer.js where we updated the isMobileDevice function to not check if the switch preventmobile is set in the url.
So we would prefer to have an option we could give on the call of new PDFTron.WebViewer so that we could use the unmodified minified version webviewer.min.js.
Background: We also have a mobile version, but on bigger Tablets it sometimes makes sense to load the desktop version. In this case WebViewer should also load in desktop mode even if "touch" is part of the user agent as on Windows Tablets.

Here the modified code we just use:

    /**
     * Detects if the current browser is on a mobile device.
     * @return {boolean} true if this page is loaded on a mobile device.
     */
    isMobileDevice: function() {
        if (location.search.toLowerCase().indexOf('disablemobile') === false) { //add by Kai Bruemmer for force desktop
            return (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i)
                    || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)
                    || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Touch/i)
                    || navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/Silk/i));
        } //add by Kai Bruemmer for force desktop
    },

Thank you in advance

Matt Parizeau

unread,
Jan 7, 2015, 3:47:55 PM1/7/15
to pdfnet-w...@googlegroups.com
Hi Kai,

Instead of modifying WebViewer.js you could set the isMobileDevice function just before you call new PDFTron.WebViewer. This way you'll be able to use WebViewer.min.js. One other thing is that indexOf will return a number, not a boolean so I believe your if check will always be false in your example code.
For example:
var mobileCheck = PDFTron.WebViewer.prototype.isMobileDevice;
PDFTron.WebViewer.prototype.isMobileDevice = function() {
   
if (location.search.toLowerCase().indexOf('disablemobile') === -1) {
       
return mobileCheck.call(this); // or add your own code here
   
}
   
return false;
};

var myWebViewer = new PDFTron.WebViewer(...

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Kai Brümmer

unread,
Jan 8, 2015, 2:44:32 AM1/8/15
to pdfnet-w...@googlegroups.com
Dear Matt,

thank you, this works fine.

Regards Kai
Reply all
Reply to author
Forward
0 new messages