I've embedded a youtube iFrame to play videos in a UIWebView web page.
The link "watch on youtube" doesn't work:
The code is:
<iframe name="player" id="player" src="http://www.youtube.com/embed/{$firstParsedVideo}?HD=1;rel=0;showinfo=0" width="279" height="155"></iframe>
where $firstParsedVideo is the video id.
I've done the same in a Cocoa Osx WebView and it works perfectly.
Thanks
here is the real solution to the problem:
the "watch on youtube" link has a target = open in new window property, to circumvent this, here is the relevant code:
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
in swift:
extension YoutubeView: WKUIDelegate {
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if !(navigationAction.targetFrame?.isMainFrame ?? false) {
webView.load(navigationAction.request)
}
return nil
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With