问题
I had to embed a YouTube video in one of my windows 8 xaml apps. I added an iframe in a webView like this. Now my problem is that when I navigate away from the page the YouTube video continues to play. Since the page in which the WebView is not present in the current view after navigation, I am not able to access the iframe as well. Is there a way to stop the video somehow once I navigate away from the page?
Thanks and Regards, Ramya
回答1:
Do you want to pause the video (and cache the page) so they can come back to where they were?
If not, then a less than elegant (but effective) option:
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { base.OnNavigatingFrom(e); wv.NavigateToString(""); }
If you want to pause the video, I believe you should be able to accomplish that goal by including some JavaScript in the YouTube IFrame API in combination with OnNavigatingFrom and a call to InvokeScript.
来源:https://stackoverflow.com/questions/13757186/youtube-video-in-an-iframe-in-webview-continues-to-play-after-navigation