vs2013 webbrowser href no effects

chun liu 21 Reputation points
2021-09-06T03:10:12.593+00:00

hi,

i try to click a href of the WebBroswer, nothing happen。 i find the class WebBrowser is sealed, how to dig it?

Developer technologies | Windows Presentation Foundation
{count} votes

3 answers

Sort by: Most helpful
  1. chun liu 21 Reputation points
    2021-09-06T07:06:17.63+00:00

    hi

    this code as follow:
    WebBrowser =mBrowser = new WebBrowser();
    mBrowser.Source = new Uri(@"http:\www.baidu.com");

    i search picture, click download no effects129488-error.png

    129490-normal.png

    this normal image, i can download by browser, but the wpf webbrowser no effects

    0 comments No comments

  2. Hui Liu-MSFT 48,681 Reputation points Microsoft External Staff
    2021-09-07T05:51:16.857+00:00

    The problem with the WebBrowser control is that by default it renders output in IE7 rendering mode.
    Internet Explorer 7 rendering will be used if you do not override the Feature Browser Emultate setting in the registry.

    Open the registry, I used the key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
    For your user (Current User) only use this key:
    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
    For all users on the computer/server use this key:
    On 64 bit app on 64 bit- or 32 bit app on 32 bit machine: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
    On 32 bit app on 64 bit machine:
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
    Value:
    11001 (0x2AF9) Internet Explorer Webpages are displayed in IE11 edge mode, regardless of the !DOCTYPE directive.

    My executable is named webBrowserDemo.exe, so I add an DWORD entry with the Name webBrowserDemo.exe and with a value 11001 (to use Internet Exlporer 11-rendering).
    129698-q.png
    The picture of result:
    You could click the download icon to download the picture successfully.
    129747-e.png

    Update:
    The HTML script error pops up an IE error message, which has almost no effect on the program. You could try to use the following code to hide it.
    The code of xaml:

    <StackPanel>  
            <WebBrowser x:Name="mBrowser" Source="http:\\www.baidu.com"   Width="800" Height="600"  />  
    </StackPanel>  
    

    The code of xaml.cs:

    public partial class MainWindow : Window  
      {  
        public MainWindow()  
        {  
          InitializeComponent();  
          HideScriptErrors(mBrowser,true);  
        }  
        public void HideScriptErrors(WebBrowser wb, bool hide)  
        {  
          var fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);  
          if (fiComWebBrowser == null) return;  
          var objComWebBrowser = fiComWebBrowser.GetValue(wb);  
          if (objComWebBrowser == null)  
          {  
            wb.Loaded += (o, s) => HideScriptErrors(wb, hide); //In case we are to early  
            return;  
          }  
          objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide });  
        }  
      }  
    

    The picture of result:
    129788-4.gif


    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.

    0 comments No comments

  3. chun liu 21 Reputation points
    2021-09-07T06:54:32.45+00:00

    hi,
    i follow your steps, but there is a error
    129802-error2.png


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.