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();
}
});
}