IFrame in htm file gives error when using MS Webbrowser Active X control

  • Thread starter Thread starter steveh01
  • Start date Start date
S

steveh01

Guest
I am trying to use the Active X control to run a local (on my PC) htm script that includes an Iframe for viewing YouTube. The htm code is taken directly from the YouTube developer's page and is shown below. When I double-click that htm file, it displays correctly in my IE browser. However, when I try to run it (it is stored at C:\video.htm) using the Navigate function of the webbrowser control, like this:

m_WebBrowser.Navigate(_T("C:\\video.htm"), NULL, NULL, NULL, NULL)

it fails with a code 0 script error that the URL https://s.ytimg.com/yts/jsbin/www-widgetapi-vflc.S5aan/www-widgetapi.js has a problem at line 0, char 0.

I've tried changing the TargetFrame to "_self" and the same error occurs. Can you tell me what I'm doing wrong? Thank you.


<html>
<body bgcolor="#FF0000">
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player" style="text-align:center"></div>


<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '400',
width: '600',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>

Continue reading...
 
Back
Top