Opera Mini Browser Detection Using Javascript










3















I have written a javascript code for my website to detect if its running on an Opera Mini browser on mobile devices. Since Opera Mini has a data saving feature, when it is enabled it sometimes doesn't load the site properly, hence I want to display a message by detecting whether the browser used is Opera Mini.



The code posted below works perfectly for Opera Mini on iOS but it doesn't work on Android. Any suggestions to make the code also work for Opera Mini on Android?






<script type="text/javascript">
function o()
var isMobile =
Opera: function()
return navigator.userAgent.match(/Opera Mini/i);
,
;
if( isMobile.Opera() ) alert('If you are using Opera Mini please disable Data Savings Mode to Have a pleasant browsing experience :)');

window.onload = o;
</script>












share|improve this question

















  • 1





    Wouldn't it be better to figure out why the site isn't loading properly and fix that issue?

    – Jeremy J Starcher
    Apr 15 '16 at 17:23











  • @JeremyJStarcher When Data Saving mode is enabled the website is sent to opera's servers where the site is compressed and then sent back to the requesting browser, the resulting site will load in a completely different manner.

    – Adhip Rebello
    Apr 15 '16 at 17:27











  • Would adding a cache-buster prevent that?

    – Jeremy J Starcher
    Apr 15 '16 at 17:44















3















I have written a javascript code for my website to detect if its running on an Opera Mini browser on mobile devices. Since Opera Mini has a data saving feature, when it is enabled it sometimes doesn't load the site properly, hence I want to display a message by detecting whether the browser used is Opera Mini.



The code posted below works perfectly for Opera Mini on iOS but it doesn't work on Android. Any suggestions to make the code also work for Opera Mini on Android?






<script type="text/javascript">
function o()
var isMobile =
Opera: function()
return navigator.userAgent.match(/Opera Mini/i);
,
;
if( isMobile.Opera() ) alert('If you are using Opera Mini please disable Data Savings Mode to Have a pleasant browsing experience :)');

window.onload = o;
</script>












share|improve this question

















  • 1





    Wouldn't it be better to figure out why the site isn't loading properly and fix that issue?

    – Jeremy J Starcher
    Apr 15 '16 at 17:23











  • @JeremyJStarcher When Data Saving mode is enabled the website is sent to opera's servers where the site is compressed and then sent back to the requesting browser, the resulting site will load in a completely different manner.

    – Adhip Rebello
    Apr 15 '16 at 17:27











  • Would adding a cache-buster prevent that?

    – Jeremy J Starcher
    Apr 15 '16 at 17:44













3












3








3


0






I have written a javascript code for my website to detect if its running on an Opera Mini browser on mobile devices. Since Opera Mini has a data saving feature, when it is enabled it sometimes doesn't load the site properly, hence I want to display a message by detecting whether the browser used is Opera Mini.



The code posted below works perfectly for Opera Mini on iOS but it doesn't work on Android. Any suggestions to make the code also work for Opera Mini on Android?






<script type="text/javascript">
function o()
var isMobile =
Opera: function()
return navigator.userAgent.match(/Opera Mini/i);
,
;
if( isMobile.Opera() ) alert('If you are using Opera Mini please disable Data Savings Mode to Have a pleasant browsing experience :)');

window.onload = o;
</script>












share|improve this question














I have written a javascript code for my website to detect if its running on an Opera Mini browser on mobile devices. Since Opera Mini has a data saving feature, when it is enabled it sometimes doesn't load the site properly, hence I want to display a message by detecting whether the browser used is Opera Mini.



The code posted below works perfectly for Opera Mini on iOS but it doesn't work on Android. Any suggestions to make the code also work for Opera Mini on Android?






<script type="text/javascript">
function o()
var isMobile =
Opera: function()
return navigator.userAgent.match(/Opera Mini/i);
,
;
if( isMobile.Opera() ) alert('If you are using Opera Mini please disable Data Savings Mode to Have a pleasant browsing experience :)');

window.onload = o;
</script>








<script type="text/javascript">
function o()
var isMobile =
Opera: function()
return navigator.userAgent.match(/Opera Mini/i);
,
;
if( isMobile.Opera() ) alert('If you are using Opera Mini please disable Data Savings Mode to Have a pleasant browsing experience :)');

window.onload = o;
</script>





<script type="text/javascript">
function o()
var isMobile =
Opera: function()
return navigator.userAgent.match(/Opera Mini/i);
,
;
if( isMobile.Opera() ) alert('If you are using Opera Mini please disable Data Savings Mode to Have a pleasant browsing experience :)');

window.onload = o;
</script>






javascript html






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 15 '16 at 17:18









Adhip RebelloAdhip Rebello

5519




5519







  • 1





    Wouldn't it be better to figure out why the site isn't loading properly and fix that issue?

    – Jeremy J Starcher
    Apr 15 '16 at 17:23











  • @JeremyJStarcher When Data Saving mode is enabled the website is sent to opera's servers where the site is compressed and then sent back to the requesting browser, the resulting site will load in a completely different manner.

    – Adhip Rebello
    Apr 15 '16 at 17:27











  • Would adding a cache-buster prevent that?

    – Jeremy J Starcher
    Apr 15 '16 at 17:44












  • 1





    Wouldn't it be better to figure out why the site isn't loading properly and fix that issue?

    – Jeremy J Starcher
    Apr 15 '16 at 17:23











  • @JeremyJStarcher When Data Saving mode is enabled the website is sent to opera's servers where the site is compressed and then sent back to the requesting browser, the resulting site will load in a completely different manner.

    – Adhip Rebello
    Apr 15 '16 at 17:27











  • Would adding a cache-buster prevent that?

    – Jeremy J Starcher
    Apr 15 '16 at 17:44







1




1





Wouldn't it be better to figure out why the site isn't loading properly and fix that issue?

– Jeremy J Starcher
Apr 15 '16 at 17:23





Wouldn't it be better to figure out why the site isn't loading properly and fix that issue?

– Jeremy J Starcher
Apr 15 '16 at 17:23













@JeremyJStarcher When Data Saving mode is enabled the website is sent to opera's servers where the site is compressed and then sent back to the requesting browser, the resulting site will load in a completely different manner.

– Adhip Rebello
Apr 15 '16 at 17:27





@JeremyJStarcher When Data Saving mode is enabled the website is sent to opera's servers where the site is compressed and then sent back to the requesting browser, the resulting site will load in a completely different manner.

– Adhip Rebello
Apr 15 '16 at 17:27













Would adding a cache-buster prevent that?

– Jeremy J Starcher
Apr 15 '16 at 17:44





Would adding a cache-buster prevent that?

– Jeremy J Starcher
Apr 15 '16 at 17:44












3 Answers
3






active

oldest

votes


















5














Never heard of Opera Mini before, but I did google for it and found https://dev.opera.com/articles/opera-mini-and-javascript/. Basically, she is using the user agent string to determine if it's opera mini by



var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);


which is very similar to your method.



However, she also suggests that you can use the window object to determine this. "Opera Mini also includes an operamini object as a property of the window object. To check for the presence of this object, use the following code."



var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


If you still can't get it to work, I would propose another approach to this. Approach this problem by trying to save using the saving feature, and if it fails, use the whatever fall back saving feature you intend to use. Therefore, whenever it's opera mini, it would be able to use the data saving feature, but when it isn't opera mini, it would use the alternative feature. Think of a try/catch here. Of course, you would want to consider the implementation when retrieving the saved data as well.






share|improve this answer






























    2














    I'm dealing with the same challenge of detecting whether the browser is implementing data saving mode by using a proxy server, but that would include more than Opera Mini in Extreme mode. It would include UC Browser Mini for Android in Speed Mode (very popular in China, India and Indonesia) and Chrome for Android's Data Saver mode. Fortunately, this mode can now be turned off on all three browsers - though many people in the developing world can't afford to, which is probably why the option is so popular.



    Dean Hume gives an example of how to detect if the user has turned data saver mode in any browser. But to get those request headers, you would need to use server side scripts, or in his example, a service worker, but not traditional Javascript.



    This answer explains how to detect UC Browser Mini in Speed Mode.



    Tiffany Brown's article on Dev.Opera, which @Jared Drake cited, does reluctantly recommend browser detection for Opera rather than feature detection. As Jared mentioned, you could use:



     var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);

    var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


    But she lists some unsupported browser events that maybe you could sniff for, such as mousemove or scroll. And she has written a whole article on Viewing and Exporting Source in Opera Mini. She points out that Opera Mini, at least with the Extreme Data Saver mode, is actually displaying OPML instead of HTML.




    Thankfully, Opera Mini offers the ability to inspect the current DOM
    tree as rendered by Opera's proxy servers. Enter server:source in the
    Opera Mini address bar to view the source of the currently loaded
    page.




    You might see something in that source that would help your detection, though I didn't see it in mine.






    share|improve this answer
































      0














      My solution is mostly a simplification of what's proposed already, tested on real device.



      Detecting Opera Mini is as simple as this:



      if(window.operamini) /* do something */ 


      or



      isoperamini = !!window.operamini; // returns true or false





      share|improve this answer






















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36653217%2fopera-mini-browser-detection-using-javascript%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5














        Never heard of Opera Mini before, but I did google for it and found https://dev.opera.com/articles/opera-mini-and-javascript/. Basically, she is using the user agent string to determine if it's opera mini by



        var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);


        which is very similar to your method.



        However, she also suggests that you can use the window object to determine this. "Opera Mini also includes an operamini object as a property of the window object. To check for the presence of this object, use the following code."



        var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


        If you still can't get it to work, I would propose another approach to this. Approach this problem by trying to save using the saving feature, and if it fails, use the whatever fall back saving feature you intend to use. Therefore, whenever it's opera mini, it would be able to use the data saving feature, but when it isn't opera mini, it would use the alternative feature. Think of a try/catch here. Of course, you would want to consider the implementation when retrieving the saved data as well.






        share|improve this answer



























          5














          Never heard of Opera Mini before, but I did google for it and found https://dev.opera.com/articles/opera-mini-and-javascript/. Basically, she is using the user agent string to determine if it's opera mini by



          var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);


          which is very similar to your method.



          However, she also suggests that you can use the window object to determine this. "Opera Mini also includes an operamini object as a property of the window object. To check for the presence of this object, use the following code."



          var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


          If you still can't get it to work, I would propose another approach to this. Approach this problem by trying to save using the saving feature, and if it fails, use the whatever fall back saving feature you intend to use. Therefore, whenever it's opera mini, it would be able to use the data saving feature, but when it isn't opera mini, it would use the alternative feature. Think of a try/catch here. Of course, you would want to consider the implementation when retrieving the saved data as well.






          share|improve this answer

























            5












            5








            5







            Never heard of Opera Mini before, but I did google for it and found https://dev.opera.com/articles/opera-mini-and-javascript/. Basically, she is using the user agent string to determine if it's opera mini by



            var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);


            which is very similar to your method.



            However, she also suggests that you can use the window object to determine this. "Opera Mini also includes an operamini object as a property of the window object. To check for the presence of this object, use the following code."



            var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


            If you still can't get it to work, I would propose another approach to this. Approach this problem by trying to save using the saving feature, and if it fails, use the whatever fall back saving feature you intend to use. Therefore, whenever it's opera mini, it would be able to use the data saving feature, but when it isn't opera mini, it would use the alternative feature. Think of a try/catch here. Of course, you would want to consider the implementation when retrieving the saved data as well.






            share|improve this answer













            Never heard of Opera Mini before, but I did google for it and found https://dev.opera.com/articles/opera-mini-and-javascript/. Basically, she is using the user agent string to determine if it's opera mini by



            var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);


            which is very similar to your method.



            However, she also suggests that you can use the window object to determine this. "Opera Mini also includes an operamini object as a property of the window object. To check for the presence of this object, use the following code."



            var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


            If you still can't get it to work, I would propose another approach to this. Approach this problem by trying to save using the saving feature, and if it fails, use the whatever fall back saving feature you intend to use. Therefore, whenever it's opera mini, it would be able to use the data saving feature, but when it isn't opera mini, it would use the alternative feature. Think of a try/catch here. Of course, you would want to consider the implementation when retrieving the saved data as well.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 15 '16 at 17:29









            Jared DrakeJared Drake

            1197




            1197























                2














                I'm dealing with the same challenge of detecting whether the browser is implementing data saving mode by using a proxy server, but that would include more than Opera Mini in Extreme mode. It would include UC Browser Mini for Android in Speed Mode (very popular in China, India and Indonesia) and Chrome for Android's Data Saver mode. Fortunately, this mode can now be turned off on all three browsers - though many people in the developing world can't afford to, which is probably why the option is so popular.



                Dean Hume gives an example of how to detect if the user has turned data saver mode in any browser. But to get those request headers, you would need to use server side scripts, or in his example, a service worker, but not traditional Javascript.



                This answer explains how to detect UC Browser Mini in Speed Mode.



                Tiffany Brown's article on Dev.Opera, which @Jared Drake cited, does reluctantly recommend browser detection for Opera rather than feature detection. As Jared mentioned, you could use:



                 var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);

                var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


                But she lists some unsupported browser events that maybe you could sniff for, such as mousemove or scroll. And she has written a whole article on Viewing and Exporting Source in Opera Mini. She points out that Opera Mini, at least with the Extreme Data Saver mode, is actually displaying OPML instead of HTML.




                Thankfully, Opera Mini offers the ability to inspect the current DOM
                tree as rendered by Opera's proxy servers. Enter server:source in the
                Opera Mini address bar to view the source of the currently loaded
                page.




                You might see something in that source that would help your detection, though I didn't see it in mine.






                share|improve this answer





























                  2














                  I'm dealing with the same challenge of detecting whether the browser is implementing data saving mode by using a proxy server, but that would include more than Opera Mini in Extreme mode. It would include UC Browser Mini for Android in Speed Mode (very popular in China, India and Indonesia) and Chrome for Android's Data Saver mode. Fortunately, this mode can now be turned off on all three browsers - though many people in the developing world can't afford to, which is probably why the option is so popular.



                  Dean Hume gives an example of how to detect if the user has turned data saver mode in any browser. But to get those request headers, you would need to use server side scripts, or in his example, a service worker, but not traditional Javascript.



                  This answer explains how to detect UC Browser Mini in Speed Mode.



                  Tiffany Brown's article on Dev.Opera, which @Jared Drake cited, does reluctantly recommend browser detection for Opera rather than feature detection. As Jared mentioned, you could use:



                   var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);

                  var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


                  But she lists some unsupported browser events that maybe you could sniff for, such as mousemove or scroll. And she has written a whole article on Viewing and Exporting Source in Opera Mini. She points out that Opera Mini, at least with the Extreme Data Saver mode, is actually displaying OPML instead of HTML.




                  Thankfully, Opera Mini offers the ability to inspect the current DOM
                  tree as rendered by Opera's proxy servers. Enter server:source in the
                  Opera Mini address bar to view the source of the currently loaded
                  page.




                  You might see something in that source that would help your detection, though I didn't see it in mine.






                  share|improve this answer



























                    2












                    2








                    2







                    I'm dealing with the same challenge of detecting whether the browser is implementing data saving mode by using a proxy server, but that would include more than Opera Mini in Extreme mode. It would include UC Browser Mini for Android in Speed Mode (very popular in China, India and Indonesia) and Chrome for Android's Data Saver mode. Fortunately, this mode can now be turned off on all three browsers - though many people in the developing world can't afford to, which is probably why the option is so popular.



                    Dean Hume gives an example of how to detect if the user has turned data saver mode in any browser. But to get those request headers, you would need to use server side scripts, or in his example, a service worker, but not traditional Javascript.



                    This answer explains how to detect UC Browser Mini in Speed Mode.



                    Tiffany Brown's article on Dev.Opera, which @Jared Drake cited, does reluctantly recommend browser detection for Opera rather than feature detection. As Jared mentioned, you could use:



                     var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);

                    var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


                    But she lists some unsupported browser events that maybe you could sniff for, such as mousemove or scroll. And she has written a whole article on Viewing and Exporting Source in Opera Mini. She points out that Opera Mini, at least with the Extreme Data Saver mode, is actually displaying OPML instead of HTML.




                    Thankfully, Opera Mini offers the ability to inspect the current DOM
                    tree as rendered by Opera's proxy servers. Enter server:source in the
                    Opera Mini address bar to view the source of the currently loaded
                    page.




                    You might see something in that source that would help your detection, though I didn't see it in mine.






                    share|improve this answer















                    I'm dealing with the same challenge of detecting whether the browser is implementing data saving mode by using a proxy server, but that would include more than Opera Mini in Extreme mode. It would include UC Browser Mini for Android in Speed Mode (very popular in China, India and Indonesia) and Chrome for Android's Data Saver mode. Fortunately, this mode can now be turned off on all three browsers - though many people in the developing world can't afford to, which is probably why the option is so popular.



                    Dean Hume gives an example of how to detect if the user has turned data saver mode in any browser. But to get those request headers, you would need to use server side scripts, or in his example, a service worker, but not traditional Javascript.



                    This answer explains how to detect UC Browser Mini in Speed Mode.



                    Tiffany Brown's article on Dev.Opera, which @Jared Drake cited, does reluctantly recommend browser detection for Opera rather than feature detection. As Jared mentioned, you could use:



                     var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);

                    var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"


                    But she lists some unsupported browser events that maybe you could sniff for, such as mousemove or scroll. And she has written a whole article on Viewing and Exporting Source in Opera Mini. She points out that Opera Mini, at least with the Extreme Data Saver mode, is actually displaying OPML instead of HTML.




                    Thankfully, Opera Mini offers the ability to inspect the current DOM
                    tree as rendered by Opera's proxy servers. Enter server:source in the
                    Opera Mini address bar to view the source of the currently loaded
                    page.




                    You might see something in that source that would help your detection, though I didn't see it in mine.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 21 '17 at 10:39

























                    answered Oct 21 '17 at 10:02









                    Michael McGinnisMichael McGinnis

                    574320




                    574320





















                        0














                        My solution is mostly a simplification of what's proposed already, tested on real device.



                        Detecting Opera Mini is as simple as this:



                        if(window.operamini) /* do something */ 


                        or



                        isoperamini = !!window.operamini; // returns true or false





                        share|improve this answer



























                          0














                          My solution is mostly a simplification of what's proposed already, tested on real device.



                          Detecting Opera Mini is as simple as this:



                          if(window.operamini) /* do something */ 


                          or



                          isoperamini = !!window.operamini; // returns true or false





                          share|improve this answer

























                            0












                            0








                            0







                            My solution is mostly a simplification of what's proposed already, tested on real device.



                            Detecting Opera Mini is as simple as this:



                            if(window.operamini) /* do something */ 


                            or



                            isoperamini = !!window.operamini; // returns true or false





                            share|improve this answer













                            My solution is mostly a simplification of what's proposed already, tested on real device.



                            Detecting Opera Mini is as simple as this:



                            if(window.operamini) /* do something */ 


                            or



                            isoperamini = !!window.operamini; // returns true or false






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 16 '18 at 4:26









                            j.j.j.j.

                            17718




                            17718



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36653217%2fopera-mini-browser-detection-using-javascript%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Top Tejano songwriter Luis Silva dead of heart attack at 64

                                政党

                                ReactJS Fetched API data displays live - need Data displayed static