Prevent links in iframe to navigate/takeover cordova webview, especially in ios

六眼飞鱼酱① 提交于 2019-12-13 11:48:29

问题


I have Cordova application which displays external content with iframe (youtube embedded video in that case)

When clicking links inside the iframe (like the youtube logo), The whole webview is navigated to the youtube website, not just the iframe. (without ability to go back, you need to kill the app), the behaviour i want to prevent.

On android, the cordova plugin api exposes onOverrideUrlLoading method, which should be able to block unwanted navigations. (have't tested it myself yet)

I haven't found similar method on ios cordova classes, nor in ios webview api. but i'm not really familiar with ios.

I've also tried (on android & ios) iframe's sandbox attribute https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe#attr-sandbox That works for preventing scripts (not that i need that atm, just to check if the attribute is doing something) but not to prevent the navigation (to enable navigation you should add allow-top-navigation and i didn't)


回答1:


Use html5 sandbox attribute, while not allowing allow-top-navigation & allow-popups

<iframe sandbox="allow-scripts allow-same-origin"...

Tested on: ios 8/7.1, android 4.4

In my previous check i've added allow-popups to the sandbox value

<iframe sandbox="allow-scripts allow-same-origin allow-popups"...


来源:https://stackoverflow.com/questions/26933233/prevent-links-in-iframe-to-navigate-takeover-cordova-webview-especially-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!