2017-07-29 132 views
1

我试图使一个无国界的,总在最前,YouTube播放器,我已经得到了几乎所有的设置,这里是我的代码:总在最前,桌面YouTube播放器

Dim html_aux As String = InputBox("Inserte URL YouTube") 
    Dim s As String() = html_aux.Split("=") 
    Dim htmlContent As String = "<html><body><iframe width='480'; height='271'; src='https://www.youtube.com/embed/" & s(1) & "'; frameborder='0';></iframe></body></html>" 
    Dim archivo As New System.IO.StreamWriter(".\Index.html", False) 
    If System.IO.File.Exists(".\Index.html") Then 
     archivo.WriteLine(htmlContent) 
     archivo.Close() 
    Else 
     MkDir(".\Index.html") 
     archivo.WriteLine(htmlContent) 
     archivo.Close() 
    End If 
    Navegador.Navigate("file:///" & IO.Path.GetFullPath(".\index.html")) 

问题是当我启动应用程序;我从WebBrowser控件得到三个错误。

脚本错误。

Error: Object doesn't support property or method 'create'.

我的猜测是这些错误来自web浏览器不支持该youtube.com/embed/url保存实际的HTML代码。

有没有办法让WebBrowser处理这些冲突?我应该停止尝试吗?

回答

1

我找到了问题的答案,添加下列头的HTML代码解决了这个问题:

<html> 
    <head> 
    <meta http-equiv='X-UA-Compatible' content='IE=edge' /> 
    ... headers code 
    </head> 
    <body> 
    ... body code 
    </body> 
</html> 

我不再获得脚本错误。

整个代码:

Public Class Form1 

Private Sub URLToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles URLToolStripMenuItem.Click 

    Dim html_aux As String = InputBox("Inserte URL YouTube") 
    Dim s As String() = html_aux.Split("=") 
    Dim htmlContent As String = 
     "<html> 
     <head> 
     <meta http-equiv='X-UA-Compatible' content='IE=edge' /> 
     </head> 
     <body> 
     <!DOCTYPE html PUBLIC '-//WAPFORUM//DTD XHTML Mobile 1.2//EN' 'http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd'> 
     <iframe width='480'; height='271'; src='https://www.youtube.com/embed/" & s(1) & "'; frameborder='0';> 
     </iframe> 
     </body> 
     </html>" 
    Dim htmlFile As New System.IO.StreamWriter(".\Index.html", False) 
    If System.IO.File.Exists(".\index.html") Then 
     htmlFile.WriteLine(htmlContent) 
     htmlFile.Close() 
    Else 
     MkDir(".\index.html") 
     htmlFile.WriteLine(htmlContent) 
     htmlFile.Close() 
    End If 
    Navegador.Navigate("file:///" & IO.Path.GetFullPath(".\index.html")) 
End Sub 

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load 
    Me.TopMost = True 
End Sub 

End Class 
相关问题