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 6702839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:02+00:00 2026-05-26T07:06:02+00:00

My HTML file has a javascript function xxx_return(), which will return a string value.

  • 0

My HTML file has a javascript function xxx_return(), which will return a string value. Is there any way i can take this value from Java layer?.

I am using SWT shell to display this html. Does SWT carry any feature to get the return values of a script function?

edit:

My code is something like below:
package test.html.simulation;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BrowserExample{
public static void main(String[] args) 
{
  Display display = new Display();
  final Shell shell = new Shell(display);
  String html="";
  Object ob=null;
    shell.setText("Browser Example");
    shell.setSize(500, 350);

        final Browser browser = new Browser(shell, SWT.NONE);
        browser.setBounds(5, 75, 600, 400);

        browser.setUrl("http://localhost/test/tryxml.html");

        shell.open();
        //System.out.println(browser.getUrl());
        //try
        {
        html=(String)browser.evaluate("returnHTML();");
        }/*catch(SWTException e)
        {
            System.out.println(e.getMessage());

        }*/
        System.out.println(html);

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
            }

        display.dispose();


}

This code gives me an SWT Exception like Object expected:

Exception in thread "main" org.eclipse.swt.SWTException: Object expected
at org.eclipse.swt.browser.WebBrowser$EvaluateFunction.function(Unknown Source)
at org.eclipse.swt.browser.WebSite.Invoke(Unknown Source)
at org.eclipse.swt.browser.WebSite$7.method6(Unknown Source)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(Unknown Source)
at org.eclipse.swt.internal.ole.win32.COM.VtblCall(Native Method)
at org.eclipse.swt.internal.ole.win32.IDispatch.Invoke(Unknown Source)
at org.eclipse.swt.ole.win32.OleAutomation.invoke(Unknown Source)
at org.eclipse.swt.ole.win32.OleAutomation.invoke(Unknown Source)
at org.eclipse.swt.browser.IE.execute(Unknown Source)
at org.eclipse.swt.browser.WebBrowser.evaluate(Unknown Source)
at org.eclipse.swt.browser.Browser.evaluate(Unknown Source)
at test.html.simulation.BrowserExample.main(BrowserExample.java:29)

In the java script i have written a function in the script tag like:

<script>
function returnHTML()
  {
   var str=document.body.innerHTML;
   //alert(str);
   return str;
  }
</script>

Can anyone find the error in this?. I don’t understand where it hits the error.

Thanks.

  • 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-26T07:06:02+00:00Added an answer on May 26, 2026 at 7:06 am

    Use an SWT Browser object. Then you can simply use String result = (String)Browser.evaluate("xxx_return();").

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

Sidebar

Related Questions

I have a HTML file that has code similar to the following. <table> <tr>
I have a html file that has invoice details I would like to know
Has anyone created HTML microformats for video and video overlays including: Video File Links
I have a HTML file upload field from which I'm reading the file name
When I add this script to a plain HTML file's HEAD section <script type=text/javascript
I am using JavaScript and jQuery. My main file has My.js and Ajax. My.js
I have an html file that accepts user inputs then uses Javascript to calculate
I'm using Jquery mobile framework. I have 2 html files which has two buttons
I has a simple JavaScript code which is consuming memory while running infinitely. Memory
Given a HTML file with the structure html -> body -> a bunch of

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.