Question Webbrowser disable bgsound

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
When you load a webpage into the webbrowser control, can you keep the bgsound tag disable? Cause i want it silence.
 
Yes, just reset the src attribute for all bgsound elements.
VB.NET:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
        For Each sound As HtmlElement In Me.WebBrowser1.Document.GetElementsByTagName("bgsound")
            sound.SetAttribute("src", String.Empty)
        Next
    End If
End Sub
 
bgsound

Thanks but the background sound still there. It seems to play before the program reach WebBrowser1_DocumentCompleted section. Also, after adding this code into the completed section. The program reach that section, it would crash right after passing the end sub.
 
Last edited:
I'm not familiar with neither of the problems you describe. That prevented bgsound play when I tested it, and didn't cause other problems. It is possible your page sets sound with some kind of client script after the page has been loaded, but that sounds strange too if we're talking about bgsound elements.
 
bgsound

i only see one place with that wave file in the source and its in the <bgsound src=""> . And its a single framed page. But it does have lots of javascript in it. For that matter, can you turn off the page's javascript? I know the script doesnt play the sound. I notice the page doesnt play the sound in my firefox even with the script on. does firefox ignore the bgsound tag?
 
You can disable Javascript in Internet Option (security setting) for computer, it is not recommended. This setting is common for Internet Explorer and WebBrowser control. I think bgsound is a IE only tag.
 
Back
Top