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

  • SEARCH
  • Home
  • 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 6868203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:24:19+00:00 2026-05-27T03:24:19+00:00

I am trying to execute JavaScript using Winforms & I would like to fetch

  • 0

I am trying to execute JavaScript using Winforms & I would like to fetch text from JavaScript code. I need to translate few lines using Google Translator service. I came across this nice Javascript code which translates given message & display it in the alert box:

<html>
<head>
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('language','1');
function init () {
google.language.translate('How are you?', 'en', 'es', function (translated) {
    alert(translated.translation);
});
}
google.setOnLoadCallback(init);
</script>
</head>
    <body>
    </body>
</html> 

Is there any way so that I can pass any string instead of ‘How are you?’ & if I can fetch the translated text (from alert box or using any var) in the C# WinForms context.

  • 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-27T03:24:19+00:00Added an answer on May 27, 2026 at 3:24 am

    Ok I did a little research. So add a webbrowser to your form, then I bet this will work well for you:

        public Form1()
        {
            InitializeComponent();
            webBrowser1.ObjectForScripting = new MyScript();
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            string myTranslatedText = "Hello, how are you?";
            webBrowser1.DocumentText = @"
                <html>
                <head>
                    <script type='text/javascript' src='http://www.google.com/jsapi'></script>
                    <script type='text/javascript'>
                        google.load('language','1');
                        function init () {
                        google.language.translate('" + myTranslatedText + @"', 'en', 'es', function (translated) {
                            window.external.CallServerSideCode(translated.translation);
                        });
                        }
                        google.setOnLoadCallback(init);                        
                    </script>
                </head>
                    <body>
                    </body>
                </html>";
        }
        [ComVisible(true)]
        public class MyScript
        {
            public void CallServerSideCode(string myResponse)
            {
                Console.WriteLine(myResponse); //do stuff with response
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute my controller from javascript using jquery... here is my jquery
I'd like to execute JavaScript code from within a C# assembly and have the
I'm trying to execute custom JS code from a Firefox extension using: function executeJS(document,
I am trying to emulate a web browser in order to execute JavaScript code
I was trying to execute the below code in my javascript and got some
Using Javascript, I'm trying to loop through an array and execute a function with
I'm trying to execute a search of sorts (using JavaScript) on a list of
i am just trying to create a link which execute some JavaScript in stead
I am trying to execute a stored procedured from a linked database in MS
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,

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.