Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Unable to execute js code injected in html through SWT Browser(Unable to execute js code injected in html through SWT Browser after disposed and create new one)
Unable to execute js code injected in html through SWT Browser [message #1858578] Sun, 09 April 2023 14:11
Thangavel M is currently offline Thangavel MFriend
Messages: 1
Registered: July 2020
Junior Member
Injected JS code with script tag in html and try to execute it through browser.execute("myJSFuction()") method.

Its working as expected for first time opening the view tab which implemented browser.
After closed and open the view tab (broswer instance and its parent composite disposed and created), html code get rendered but the injected js script not get loaded.

Tried clearing the html text before dispose the browser instance.

@Override
	public void createPartControl(Composite parent) {
		Browser browser = new Browser(parent, SWT.NATIVE);
		browser.setJavascriptEnabled(true);
		setHtml(browser);
		setBrowserFuntion(browser);
		browser.addMenuDetectListener(new MenuDetectListener() {
			public void menuDetected(MenuDetectEvent e) {
				e.doit = false;
				}
				});
		browser.addStatusTextListener(new StatusTextListener() {
			@Override
			public void changed(StatusTextEvent event) {
				String statusText = event.text;
//				System.out.println(event);
			}
		});

      // Add a ProgressListener to update the ProgressBar
      browser.addProgressListener(new ProgressListener() {
          public void changed(ProgressEvent event) {
//              if (event.total == 0)
//                  return; // Page hasn't started loading yet
//              int ratio = (event.current * 100) / event.total;
//              progressBar.setSelection(ratio);
          }
          public void completed(ProgressEvent event) {
              // Hide the ProgressBar when the page is loaded
//              progressBar.setVisible(false);
        	  browser.execute("myJSFunction()");
          }
      });

		
		parent.addDisposeListener(new DisposeListener() {
			
			@Override
			public void widgetDisposed(DisposeEvent arg0) {
				// TODO Auto-generated method stub
				browser.setText("");
				Browser.clearSessions();
				browser.close();
				browser.dispose();
			}
		});
		
	}
Previous Topic: [Windows 10] - OLE - Problem when embedding Microsoft Application as excel in SWT Frame
Next Topic:No drawing on AWT canvas using SWT_AWT bridge on Linux/wayland
Goto Forum:
  


Current Time: Mon Nov 04 09:31:33 GMT 2024

Powered by FUDForum. Page generated in 0.03377 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top