question

KiyoshiNakano-3469 avatar image
0 Votes"
KiyoshiNakano-3469 asked KiyoshiNakano-3469 commented

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

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).





dotnet-visual-basicwindows-forms
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Since the WebBrowser is in your form, then it is under your control and maybe you can affect the behaviour programmatically. How is the content assigned to WebBrowser in real circumstances, by navigation to some URL? Maybe you can remove the unwanted null characters from the string.

0 Votes 0 ·

The content is actually fetched by the html (VBScript) via ActiveX (ocx), so I think the WebBrowser cannot do anything with the data. We understand that the problem is the irregular case of the data having a null (since this never occurred in years until now), so maybe we can negotiate to just modify the VBScript to remove the null (or the DLL providing data which has null) but that will be the last resort.

We were hoping that maybe the WebBrowser cotrol can just behave exactly like IE8. If it is not possible, then maybe using the WebBrowser control is not an option to emulate IE8 on a custom browser running in Windows 10.

0 Votes 0 ·
cheong00 avatar image
0 Votes"
cheong00 answered cheong00 commented

How about replacing null with U+FEFF(&#65279; zero-width non-breaking space) or U+2060(&#8288; word joiner) before rendering?

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

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Actually the data with null character is retrieved from another source and displayed in the html, and we cannot modify the html/script to change the display. The problem raised was that this specific page which retrieves a data with null was displaying correctly in IE8, but when we switched to using our custom browser the data was not displayed correctly.

Does this mean this is the expected behavior of the WebBrowser control?
I was hoping there was a way for the WebBrowser control to behave exatly as IE8.

0 Votes 0 ·
cheong00 avatar image cheong00 KiyoshiNakano-3469 ·

I mean you should change the source of data to avoid null character before returning, then in your code to process data, use the new separator character instead.

1 Vote 1 ·

Yes, if we change the source data to not output then our problem will be solved. But the main concern is that why does IE8 behave differntly with the WebBrowser control.

We can request to modify the source data but there is still a concern if there are other cases in which the WebBrowser control cannot behave exactly as IE8 (since we substituted IE8 with custom browser in our application).

If there is no way for WebBrowser control to behave like IE8 (in this scenario), then we will just give up and request to just change the source data.

0 Votes 0 ·
Show more comments
DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered KiyoshiNakano-3469 commented

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.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Daniel,
We actually already tried those solutions (I wrote in the "Solutions tried") and when we alerted the browser version from script it returned IE 8 (MSIE 8.0) successfully, but the behavior is still different,

0 Votes 0 ·
DewayneBasnett-7583 avatar image
0 Votes"
DewayneBasnett-7583 answered KiyoshiNakano-3469 commented

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.




· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the reference. Yes, we understand that the problem is the source data, and we will be fixing that. Our main concern is that if WebBrowser control can fully replicate IE8 behavior. It seems like everyone is always pointing on the source data as the issue so guess it's safe to assume that the WebBrowser control cannot replicate IE8 behavior and we'll just fix/patch any difference that will come in the future just like this.

0 Votes 0 ·
cheong00 avatar image cheong00 KiyoshiNakano-3469 ·

Microsoft has moved the VBScript engine out-of-process from IE since 2017 to get rid of it. In IE11 VBScript is default disabled.

Since it now has to pass any data to engine by string format that's accepted by it, there is no way to workaround this limitation.

Also note that since Microsoft is about to remove IE11 in Win10 (2021-06-15, that is 5 days later), and VBScript is never supported in Edge (no matter the original one or Chrome-based one), you're strongly recommended to replace VBScript in your web pages with Javascript ASAP.


0 Votes 0 ·

Thanks for the explanation. If there's no workaround we'll just have to explain this to the client and fix the handler of the source data to prevent null characters from passing to the html/script side.

Regarding VBScript, it would be hard to switch since our huge (very old) system is using it and I think it would never be changed, thus we are using a custom browser to emulate older versions of IE.

I guess we can call this issue closed.

0 Votes 0 ·