endless icon indicating copy to clipboard operation
endless copied to clipboard

iframe content doesn't behave like top level: long-press and new-window links

Open adam-p opened this issue 8 years ago • 0 comments

injected.js only gets injected in the top-level page, not in iframes. This means that the functionality it provides is not available inside iframes.

So, these are missing (at least):

  • long-press menu: The default/native webview long-press menu is shown, rather than the custom menu. The items on it aren't wired up properly, so they either do nothing or behave oddly.
  • target="_blank" handling: Links with that property will not open in a new tab.

We played with injecting injected.js at every level (top and frames). It fixes the target="blank" problem, but the long-press menu problem remains. This is because when the ObjC function elementsAtLocationFromGestureRecognizer calls the JS function elementsAtPoint, it will only ever call the top-level page's function (because that's how stringByEvaluatingJavaScriptFromString works). So elementsAtPoint would have to do something like: detect that the given coordinates are inside an iframe, change the coordinates to be relative to the frame's location, communicate with the frame (probably via postMessage) to get it to call elementsAtPoint, and then report back to the ObjC. (In addition to the other complications, this will go from being a synchronous call to async.)

You can fool around with the iframe behaviour here:
http://nunzioweb.com/iframes-example.htm (Example 3)

adam-p avatar Apr 20 '17 18:04 adam-p