Click here to Skip to main content
15,889,863 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: LINQ: How To Make Order By Conditional? Pin
Richard MacCutchan27-May-18 1:05
mveRichard MacCutchan27-May-18 1:05 
GeneralRe: LINQ: How To Make Order By Conditional? Pin
Alan Burkhart29-May-18 14:42
Alan Burkhart29-May-18 14:42 
AnswerRe: LINQ: How To Make Order By Conditional? Pin
Richard Deeming30-May-18 9:58
mveRichard Deeming30-May-18 9:58 
GeneralRe: LINQ: How To Make Order By Conditional? Pin
Mycroft Holmes30-May-18 14:27
professionalMycroft Holmes30-May-18 14:27 
GeneralRe: LINQ: How To Make Order By Conditional? Pin
Richard Deeming31-May-18 1:15
mveRichard Deeming31-May-18 1:15 
GeneralRe: LINQ: How To Make Order By Conditional? Pin
Alan Burkhart31-May-18 7:18
Alan Burkhart31-May-18 7:18 
GeneralRe: LINQ: How To Make Order By Conditional? Pin
Alan Burkhart31-May-18 7:33
Alan Burkhart31-May-18 7:33 
QuestionWebBrowser Javascript Error handing via HtmlWindow works in IE8 mode but not in IE10 or Edge. Pin
Jeffrey Cobb26-May-18 15:55
Jeffrey Cobb26-May-18 15:55 
I have an HTML file that I'm loading into a WebBrowser control via .Navigate(myfileURI) which works fine.
In my application I'm trapping Javascript errors in order to handle them myself via the code on this web page:
https://msdn.microsoft.com/en-us/library/system.windows.forms.htmlwindow.error%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

This seems to work fine until I tweak the compatibility mode in the html file. For example, using the meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=8">

or even no such tag at all works fine. However when I use the meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=10">
or
<meta http-equiv="X-UA-Compatible" content="IE=edge">

the code to trap Javascript errors no longer works.

I'd really like to know why?

I'd prefer to use IE10 or edge for access to better Javascript functionality.

Here's the code I used in a simple Visual Basic Form and WebBrowser control as well as a simple "test.html" file below it:
(Note: the "a.args" line in the html file is suppose to deliberately throw an error)

Thanks in advance,
Jeff

Form1.vb
Imports System.Runtime.InteropServices

Public Class Form1

    <ComVisible(True)>
    Public Class JSRequester

        Public this As Form1

        Public Sub log(s As String)
            Debug.Print(s)
        End Sub

        Public Sub send(MFSYS As String)
            Debug.Print("[" + this.Name + "]  INPUT   <" + MFSYS + ">")
            this.WebBrowser1.Document.InvokeScript("eval", New Object() {"alert('Hello Script!');"})
        End Sub

        Public Sub New(frmSender As Form1)
            this = frmSender
        End Sub
    End Class

    <ComVisible(False)>
    Public bMouseDown As Boolean = False
    Public bFormActivated As Boolean = False
    Public WithEvents ScriptWindow As HtmlWindow

    Private Sub nav(uriFile As Uri)
        Debug.Print("STARTED")
        WebBrowser1.Navigate(uriFile)
    End Sub

    Private Sub SuppressScriptErrors()
        If (WebBrowser1.Document IsNot Nothing) Then
            ScriptWindow = WebBrowser1.Document.Window
        End If
    End Sub

    Private Sub ScriptWindow_Error(ByVal sender As Object, ByVal e As HtmlElementErrorEventArgs) Handles ScriptWindow.Error
        MessageBox.Show("Suppressed error!")
        e.Handled = True
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        '*** Change this to your path ***
        Dim strAppPath As String = "D:\dev\vbnet\SuppressJavascriptErrors"
        Dim uriFile As New Uri("file:///" + strAppPath + "\test.html")
        Me.WebBrowser1.ObjectForScripting = New JSRequester(Me)
        nav(uriFile)
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Debug.Print("COMPLETED")
    End Sub

    Private Sub WebBrowser1_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
        Debug.Print("NAVIGATED")
        SuppressScriptErrors()

    End Sub
End Class


test.html
<!DOCTYPE html>
<html>
<head profile="http://gmpg.org/xfn/11">
	<meta http-equiv="X-UA-Compatible" content="IE=8"> <!-- change this to "10" or "edge" it FAILS -->
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
	<META HTTP-EQUIV="EXPIRES" CONTENT="0">
	<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>YouTube Viewer</title>
	<link rel="stylesheet" type="text/css" href="ytv.css">
</head>
	<body onload="init();">
		<script type="text/javascript">
			function testme() {
				a.args = "hello" // deliberately throw error
				return;
			}

			function init() {
				window.external.log(">>>HELLO DEBUG...");
				window.external.send(">>>HELLO SENDER...");
				testme();
				document.write("<h1>Hello World!</h1>");
			}
		</script>
	</body>
</html>

QuestionOutlook Mail Drag Drop into Textbox of a Win Form Pin
HPS-Software24-May-18 18:41
HPS-Software24-May-18 18:41 
AnswerRe: Outlook Mail Drag Drop into Textbox of a Win Form Pin
Richard Deeming25-May-18 2:35
mveRichard Deeming25-May-18 2:35 
GeneralRe: Outlook Mail Drag Drop into Textbox of a Win Form Pin
HPS-Software26-May-18 20:51
HPS-Software26-May-18 20:51 
GeneralRe: Outlook Mail Drag Drop into Textbox of a Win Form Pin
Eddy Vluggen26-May-18 23:05
professionalEddy Vluggen26-May-18 23:05 
GeneralRe: Outlook Mail Drag Drop into Textbox of a Win Form Pin
HPS-Software27-May-18 18:14
HPS-Software27-May-18 18:14 
QuestionSave in datagriedview in application Pin
Member 1361197220-May-18 8:13
Member 1361197220-May-18 8:13 
AnswerRe: Save in datagriedview in application Pin
Dave Kreskowiak20-May-18 11:40
mveDave Kreskowiak20-May-18 11:40 
GeneralRe: Save in datagriedview in application Pin
Member 1361197221-May-18 1:26
Member 1361197221-May-18 1:26 
AnswerRe: Save in datagriedview in application Pin
Richard Deeming21-May-18 2:11
mveRichard Deeming21-May-18 2:11 
GeneralRe: Save in datagriedview in application Pin
Member 1361197222-May-18 6:00
Member 1361197222-May-18 6:00 
QuestionWhat am I missing with Clone()? Pin
mo149218-May-18 13:48
mo149218-May-18 13:48 
AnswerRe: What am I missing with Clone()? Pin
Eddy Vluggen18-May-18 14:03
professionalEddy Vluggen18-May-18 14:03 
GeneralRe: What am I missing with Clone()? Pin
mo149218-May-18 14:10
mo149218-May-18 14:10 
GeneralRe: What am I missing with Clone()? Pin
Eddy Vluggen18-May-18 14:13
professionalEddy Vluggen18-May-18 14:13 
AnswerRe: What am I missing with Clone()? Pin
Richard Deeming21-May-18 2:06
mveRichard Deeming21-May-18 2:06 
QuestionHow can obtaing the filename of spool job? Pin
bGuidi7-May-18 4:59
professionalbGuidi7-May-18 4:59 
QuestionExternal Media player sdk for vb Pin
Asanka Akash Sovis5-May-18 22:27
professionalAsanka Akash Sovis5-May-18 22:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.