vendredi 20 janvier 2017

Test Javascript in mobile browser

Before you down vote my question, I am novice and just want a pointer. I have written a plain Javascript code that will run on different Desktop and on Mobiles.

For Desktop, I can just open the browser console and test my Javascript code. But how can I test for mobile devices. My code is mostly failing for mobile devices which I am able to figure out when I check the user agent.

Here is a simple piece of code, that extract word counts from a web page.

function countWords() {
    try {
        if (top.document && top.document.querySelector("body")) {
            var _body = top.document.querySelector("body");
            var words =  _body.textContent || _body.innerText; //For old firefox, innerText does not work

            if (words) {
                words = words.replace(/\n/g,'');
                var filteredWords = words.match(/\S+/g);
                if (filteredWords && filteredWords.length > 0) {
                    userDetail.wordCount = filteredWords.length;
                }
            }
        }
    } catch (err) {
        processError("countWords", err);
    }
}

This code is not working on on mobile devices.

Aucun commentaire:

Enregistrer un commentaire