Opening popup links in UIWebView, possible?

前端 未结 4 987
旧时难觅i
旧时难觅i 2020-12-01 08:53

I have a UIWebView which I\'m using as an embedded browser within my app.

I\'ve noticed that links in webpages that open new windows are ignored without any call int

4条回答
  •  遥遥无期
    2020-12-01 09:31

    I ran into this as well, and HTML rewriting was the best solution I could come up with. The biggest issue that I ran into with that approach is that the web browser is interactive for up to a couple of seconds until the webViewDidFinishLoad: method is called, so the links seem to be broken for a few seconds until they're rewritten.

    There's three areas that I rewrote: links, form posts, and calls to window.open().

    I used a similar approach to the first code snipped in Jasarian's answer to overwrite the target for links and forms by iterating over tags and forms. To override window.open, I used code similar to the following:

    var oldWindowOpen = window.open;
    window.open = function(url, sName, sFeatures, bReplace) {
      oldWindowOpen(url, '_self');
    };
    

提交回复
热议问题