Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 524
Bnaya Avatar asked Nov 14 '14 15:11

Bnaya


1 Answers

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"...
like image 158
Bnaya Avatar answered Nov 14 '22 22:11

Bnaya