检测iOS是否使用webapp
我想知道是否有可能检测一个iOS用户是否使用该Web应用程序,或只是通过Safari浏览器访问正常的方式。
我想要实现的原因是,当用户点击一个链接时,在iOS webapp上,他将被redirect到Safari浏览器。 所以我使用下面的解决方法,让他留在webapp(防止切换到Safari浏览器)。
$( document ).on("click",".nav ul li a", function( event ){ // Stop the default behavior of the browser, which // is to change the URL of the page. event.preventDefault(); // Manually change the location of the page to stay in // "Standalone" mode and change the URL at the same time. location.href = $( event.target ).attr( "href" ); } );
但是我想要这个解决方法只发生在用户使用webapp时,我希望它是webapp用户的条件。 所以不要在默认的Safari浏览器。
你必须通过使用一些javascript来检测这个:
<script> if ( ("standalone" in window.navigator) && // Check if "standalone" property exists !window.navigator.standalone // Test if using standalone navigator ){ // .... code here .... } </script> </head>
在这里可以find: 确定网站是作为networking应用程序打开还是通过常规的Safari浏览器在iPad上?
答案中使用的来源是这个 。
iOS和Chrome的Web应用程序的行为不同,这是我来到以下的原因:
isInWebAppiOS = (window.navigator.standalone == true); isInWebAppChrome = (window.matchMedia('(display-mode: standalone)').matches);