65.9K
CodeProject is changing. Read more.
Home

WebBrowserControl Shortcuts Are Not Working (WinForms)

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Oct 30, 2015

CPOL
viewsIcon

9062

After upgrading from Internet Explorer 8 to Internet Explorer 11, WebBrowserControl shortcuts stopped working. After a lot of research, I found out the root cause of this and also a trick to resolve this issue.

Introduction

One fine day, I came across a strange issue that WebBrowserControl shortcuts were not working after I upgraded from Internet Explorer 8 to Internet Explorer 11.

I started Googling why shortcurts (ex: CTRL+C, CTRL+V) are not working. There were some suggestions saying overwrite the keypress event and write your own logic to handle the shortcuts. Overwriting keypress event may not be a bad idea. However, if we support 100 shortcuts, we need to write code to handle all of those.

After a lot of research, I finally found that this is a compatibility issue. Adding meta tag to the webbrowser control solves this problem.

I am sharing this experience so that if anyone faces the same issue, this trick will helps them.

Using the Code

Before navigating the URL, write meta into webbrowser's documenttext property as follows:

//Setting compatible mode of IE.
this.m_oWebBrowser.DocumentText = 
                  @"<html>
                  <head><meta http-equiv=""X-UA-Compatible"" 
                  content=""IE=IE11"" /> </head>
                  <body></body>
                  </html>";
this.m_oWebBrowser.Navigate(szURL);