javascripthtmlmobile

Displaying an Alert for All Mobile Devices


I am creating a website which suits to computers (Which use a mouse [Pointer on screen] ). It is not suitable for mobile devices (which have touch screens), because it has some effects like on mouse over/leave. When a user visits the site using a mobile device, it should display a message that 'This Website has a better look with a Computer'.

Js Part

<script language="Javascript">
window.onload=function {
    alert("Visit this on a Computer for Better View");
}
</script>

HTML Part

<HTML>
    <BODY>
        <p>content</p>
    </BODY>
</HTML>

Solution

  • Try This :

        <script language="Javascript">
        window.onload=function(){
        var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
        if (mobile) {
            alert("Visit this on a Computer for Better View");              
        } else {
    
        }
      }
      </script>