Click here to Skip to main content
15,881,757 members
Articles / Programming Languages / C#
Tip/Trick

WebBrowserControl Shortcuts Are Not Working (WinForms)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
30 Oct 2015CPOL 8.6K   3   4
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:

C++
//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);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Allscripts
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionEmulation per Registry Key Pin
include762-Nov-15 2:13
include762-Nov-15 2:13 
AnswerRe: Emulation per Registry Key Pin
Siva Sankar Gorantla17-Nov-15 15:49
professionalSiva Sankar Gorantla17-Nov-15 15:49 
QuestionCompatibility modes... Pin
dandy7230-Oct-15 6:57
dandy7230-Oct-15 6:57 

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.