Reputation: 1119
I have the following code:
webBrowser1.Navigate("about:blank");
string _embeddedpage = "<html><head></head><body bgcolor=\"black\"><iframe height=\"300\" width=\"600\" src=\"http://www.youtube.com/embed/9bZkp7q19f0\"></iframe></body></html>";
webBrowser1.Document.Write(_embeddedpage);
Unfortunately no matter what I try the iframe doesn't load. The HTML works fine if I save it out to a HTML file and then run it, and it also works fine if i then point the webBrowser control at the physical html file.
However when doing it like this and creating the HTML from within the application it just won't play ball.
Upvotes: 1
Views: 6297
Reputation: 19717
I have just tried it myself. This code will work for you:
private void Form1_Load(object sender, EventArgs e)
{
string _embeddedpage = @"
<html>
<body>
<iframe class='youtube-player' type='text/html' width='640' height='385'
src='http://www.youtube.com/embed/9bZkp7q19f0\' frameborder='0'>
</iframe>
</body>
<html>";
webBrowser1.DocumentText = _embeddedpage;
}
Upvotes: 3
Reputation: 78175
You have a race condition between loading "about:blank" and writing into the document.
You should write after the page has loaded, e.g. from Navigated
event handler.
Upvotes: 1