Cordova allow-navigation vs allow-intent

Navigation Allow List

This controls which URLs the WebView itself can be navigated to. It applies only to top-level navigations.
控制哪些url可以在cordova WebView中直接訪問(wèn)。

Intent Allow List

This controls which URLs the app is allowed to ask the system to open.
控制哪些url可以交給系統(tǒng)打開(kāi)。這個(gè)url請(qǐng)求是直接調(diào)用 [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]。如:
<allow-intent href="http:*" />,跳出當(dāng)前cordova應(yīng)用,調(diào)起系統(tǒng)默認(rèn)瀏覽器打開(kāi)url。
<allow-intent href="tel:*" />,系統(tǒng)調(diào)起打電話的請(qǐng)求。
<allow-intent href="iosamap:*" />,打開(kāi)高德地圖。

allow-navigation優(yōu)先級(jí)更高

如同時(shí)設(shè)置<allow-navigation href="http:*" />和<allow-intent href="http:*" />,會(huì)在當(dāng)前WebView中跳轉(zhuǎn)到對(duì)應(yīng)http url,不會(huì)調(diào)起系統(tǒng)瀏覽器打開(kāi)url。

如果設(shè)置了<allow-navigation href="*" />,則所有請(qǐng)求都通過(guò)當(dāng)前cordova WebView訪問(wèn),allow-intent設(shè)置的系統(tǒng)跳轉(zhuǎn)都會(huì)被allow-navigation攔截,而大多數(shù)allow-intent設(shè)置的第三方協(xié)議,如iosamap://(高德地圖)在cordova WebView中是無(wú)法打開(kāi)的。

所以盡量不要設(shè)置<allow-navigation href="*" /> ??!
可以設(shè)置:

<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
...

<allow-intent href="tel:*" />
<allow-intent href="iosamap:*" />
...
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容