2017-07-29 79 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 
相關問題