div innerHtml string after null character ignored in WebBrowser control but not in IE8

Roland Jude Macasero 21 Reputation points
2021-06-08T01:15:02.84+00:00

same question in detail I posted in stackoverflow: div-innerhtml-string-after-null-character-ignored-in-webbrowser-control-but-not

The problem is that when setting string data which has a null in the middle, the succeeding characters after the null are not displayed in our custom browser using WebBrowser control, but IE8 was able to display all characters (it ignored the null).

Here's a sample script to replicate the issue:

Dim str
Sub Window_OnLoad()

str= "<TABLE >" & _
"<TR ><TD >0</TD></TR>" & _
"<TR ><TD >1" & chr(&H0) & "</TD></TR>" &_
"<TR ><TD >2</TD></TR><TR ><TD >3</TD></TR></TABLE>"

MsgBox str

document.all.mydiv.innerHtml = str
End Sub

(the "str" string contains a null character in the middle.)

Output (IE8):
0
1
2
3

Output (WebBrowser control):
0
1

In our application, the 2nd data retrieved (in the example above "1") that is set to the table element contains null after it, and what happens in the WebBrowser control is that the data after the null are discarded, thus not being able to print the whole data on the table. However, in IE8, it just seems to ignore the null and display the whole data on the table. Is there some way to make the WebBrowser control behave like in IE 8?

Solutions tried\Investigation results:

  1. We already set the Browser Emulation correctly so that the web browser will behave like IE 8 but it still not working. (tried both 8000 and 8888)
  2. We tried to use meta X-UA-Compatible instead of the Browser Emulation, but still not working. (tried both "IE=8" and "IE=EmulateIE8")
  3. We tried setting all kinds of DOCTYPE but it also doesn't work.
  4. In the sample code above I put a MsgBox to see the data to be set in the inner HTML and IE8 did not alert the data after the null. It was only able to ignore the null when setting it to the inner HTML. Could this be a special behavior of the inner HTML in IE?
  5. I don't know if necessary but I tried to translate the code in javascript and still got the same results for both IE8 and WebBrowser control.
  6. Tried to set User-Agent with the same as IE8 when navigating but the result is still the same (characters after null are discarded).
Developer technologies Windows Forms
Developer technologies VB
{count} votes

3 answers

Sort by: Most helpful
  1. cheong00 3,486 Reputation points Volunteer Moderator
    2021-06-08T02:22:24.807+00:00

    How about replacing null with U+FEFF( zero-width non-breaking space) or U+2060(⁠ word joiner) before rendering?

    Null character means "end of string" in traditional "null terminated string" using in C and other languages.


  2. Daniel Zhang-MSFT 9,651 Reputation points
    2021-06-09T01:47:08.85+00:00

    Hi KiyoshiNakano-3469,
    You can try to add some js or modify the registry to use IE8.
    More details you can refer to the following threads:
    Webbrowser control behaving different than IE
    Web Browser component is IE7 not IE8? How to change this?
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Dewayne Basnett 1,381 Reputation points
    2021-06-09T16:17:48.683+00:00

    If all else fails you can read the documentation.

    https://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#text-0

    It is abundantly clear from the documentation that html should NOT contain null characters. The fact that one browser does or does not display correctly today is not relevant, tomorrow none of them may. IMHO if you are doing anything but cleaning out the invalid characters you are making a mistake.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.