11
<!doctype html> 
<html> 
<head> 
<title>page</title> 
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/> 
<meta name="apple-mobile-web-app-capable" content="yes" /> 

<meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
</head> 
<body> 
<script> 
function goToPage() { 
    var pageUrl = 'http://www.google.com/'; 
    window.open(pageUrl); 
} 
</script> 
<div id="installBtn" onclick="goToPage()">go to page</div> 
</body> 
</html> 

預期的操作是:當觸摸div時,會打開一個新窗口。 這段代碼在iPhone的Safari瀏覽器中效果很好。如何在iPhone的獨立(全屏)模式下打開一個新窗口

但是當我點擊「+」 - >「添加到主屏幕」,然後按「轉到頁面」,沒有窗口打開,頁面加載在同一屏幕上。

如何強制,by javascript,在獨立模式下打開一個新窗口?

回答

-9

你走了! (如果你仍然需要它)

<script> 
    if(window.navigator.standalone === true) 
    document.write('Standalone'); 
    else 
    document.write('Web browser'); 
</script> 

R.

+2

沒有太大的幫助...... – 2012-04-27 11:37:21

+1

歡迎堆棧溢出:-) 請看[答]。您應該提供一些信息,說明爲什麼您的代碼可以解決問題。 僅有代碼的答案對社區沒有用處。 – JimHawkins 2017-02-09 09:23:06

+0

那麼這是2012年的消息,但足夠公平!此代碼測試Web引擎是否在獨立模式下使用。 AFAIK僅支持iOS – 2017-02-09 10:45:02

1

以下問題確實提到一個可能的JavaScript解決方案出前投票的答案,它構造錨元素和調度上的「click」事件。

問:Force link to open in mobile safari from a web app with javascript
答:https://stackoverflow.com/a/8833025/1441046

或者,如果你可以使用一個錨元素(我知道你問如何做到這一點在JavaScript),你可以做到以下幾點:

<a id="installBtn" href="http://www.google.com/" target="_blank">go to page</a> 

其他相關問題:

iPhone window.open(url, '_blank') does not open links in mobile Safari

0

這適用於我。從html只從JS請求時不起作用。

window.open('[url]','_system'); 
+0

這不適用於Safari瀏覽器 – hiphapis 2014-08-25 06:29:33

0

可以使用childbrowser在獨立模式

打開或者您可以使用此

window.location = url(your Url); 
相關問題