Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:51:45+00:00 2026-05-26T14:51:45+00:00

There is a great tutorial here about windows forms How to inject Javascript in

  • 0

There is a great tutorial here about windows forms

How to inject Javascript in WebBrowser control?

I tried it and it works great

But the problem is the objects used there is not recognized at wpf application. So what i am asking is what is the equivalent of the function below in wpf application. Thank you.

HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
string srJquery = File.ReadAllText("jquery.txt");
element.text = srJquery;
head.AppendChild(scriptEl);  

the function above is working perfectly at windows form application c# 4.0 but the used objects such as HtmlElement is not recognized at WPF application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:51:45+00:00Added an answer on May 26, 2026 at 2:51 pm

    Does this work?

        private void WebBrowser_LoadCompleted
           (object sender,
            System.Windows.Navigation.NavigationEventArgs e)
        {
            var webBrowser = sender as WebBrowser;
    
            var document
               = webBrowser.Document as mshtml.HTMLDocument;
            var ahref
               = document.getElementsByTagName("A").Cast<mshtml.IHTMLElement>().First();
            ahref.setAttribute(
               "onmouseenter",
               "javascript:alert('Hi');", 1);
        }
    

    You need is Microsoft.mshtml (the .net API and not MS office one) reference.

    Also please see this code for WPF webbrowser control that uses ObjectForScripting property of WebBrowser which can help you in injecting javascript…

    http://blogs.msdn.com/b/wpf/archive/2011/05/27/how-does-wpf-webbrowser-control-handle-window-external-notify.aspx

    Let me know if this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know nothing about medical records but im sure there's great opportunity in it
There are a number of great Javascript libraries\frameworks out there (jQuery, Prototype, MooTools, etc.),
I'm working in gvim with sessions and tabs, and everything works great. However there
I like javascript, but I have problem with learning it :) I mean, i
There's a great tutorial on IBM's website which walked me through a simple search/results
So there is a great open source tutorial on creating TreeNode class . It
WPF is great because there are many ways to achieve your goals. For example,
While there are a handful of great programs for ISV Startups (BizSpark, Emplower ISV,
WiX is great in that there is no GUI, you just write the installer
Reflection API is great thing out there to manipulate the OOP stuff and looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.