Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

c# - Script runs slower in the dotnet WebBrowser control

I use the WebBrowser control and Smooth Div Scroll in my winforms application to render a html marquee. I downloaded the sample and added

autoScrollingInterval: 3

to

$("div#makeMeScrollable").smoothDivScroll({
    autoScrollingMode: "onStart"
});

to make it move faster. When I open the sample in IE it works just fine but when I use the WebBrowser control and call the navigate method the scroller moves much slower.

What is causing this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As I understand it, the issue you are dealing with is a versioning issue with the WebBrowser Control rendering in IE 7 Standard Mode and the actual WebBrowser you are using in IE is either IE 8 or IE 9, and it works there, yet your JQuery/JavaScript or CSS inclusions are not working in IE 7.

Let me tell you this straight up. The default rendering engine on the webbrowser control is fixed to ensure compatibility across all platforms.

Basically, if you're installed browser is IE 7 - IE 9, then the rendering engine used is IE 7.0 only (by default).

If, however, your installed IE version is IE 6 or below, then the rendering engine used is IE 4.0 (not kidding), unless of course you set it otherwise.

There is a misconception that WebBrowser control uses whatever is currently installed (current IE version) but this is not true, since they do this to reduce backward compatibility issues. You can see (as proof) that this really is your problem by going to www.whatsmyuseragent.com in your normal browser, and then going to that website again in your WebBrowser control, you will see that it says MSIE 7.0 :).

You can set it to use the current installed version of internet explorer, either using a META tag in-page, or editing the Registry on the machine where the webbrowser control will run (editing for Current_User and Local_Machine will both work).

WebBrowser control will (normally) use whatever version of IE you have installed, but for compatibility reasons it will render pages in IE7 Standards mode by default.

If you want to take advantage of new IE9 features, you should add the meta tag <meta http-equiv="X-UA-Compatible" content="IE=9" > inside the <head> tag of your HTML page.

This meta tag must be added before any links to CSS, JavaScript files etc that are also in your <head> to work properly though (only other <meta> tags or the <title> tag can come before it).

An alternative is to add a registry entry to:

HKLM > SOFTWARE > Microsoft > Internet Explorer > Main > FeatureControl > FEATURE_BROWSER_EMULATION

And in there add 'YourCompiledApplicationName.exe' with value '9000' to force the WebBrowser control to display pages in IE9 mode. Though there are other values you can use too too, note that these docs aren't entirely accurate as it does not seem possible to get a page to render in IE 8 mode whatever value you use. (Note: YourCompiledApplicationName.exe must be the EXE file name that you compile which contains your WebBrowser Control, it will only work for the file name that you've included in the registry). Also, it wouldnt hurt to add vshost.exe and YourCompiledApplicationName.exe.svchost so it works when run through your IDE, and also, If your app is running under 64bit Windows, you likely should also set the following DWORD under the following registry path to the same value (as per the 32bit path):

HK[LM|CU] SOFTWARE Wow6432Node Microsoft Internet Explorer Main FeatureControl FEATURE_BROWSER_EMULATION

Adding the registry key to the same path in HKCU instead of HKLM will also work - this is useful as writing to HKLM requires admin privileges where as HKCU does not.

Not sure if when IE 10.0 comes out if the WebBrowser controls default engine will go to 10.0 (if 10.0 is installed on system of course) or if it will remain as IE 7.0 even after IE 10.0 is released, we will have to see once it comes out. However, if we guess based on previous experience, i suspect IE 10.0 will be the last version that uses IE 7.0 rendering engine, and when IE 11 comes out, the default rendering engine will remain as IE 11 for all versions of IE between IE 11 & IE 14. This is just a guess by extrapolating what they've done in the past.

For more information on the values you can set the registry to,check this out:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...