Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » browser and javascript
browser and javascript [message #529021] Thu, 22 April 2010 12:16 Go to next message
Filip is currently offline Filip
Messages: 16
Registered: March 2010
Location: Czech Republic
Junior Member
Hello,
is there any way how to catch or disable some javascript functions on the pages beying loaded in the browser. E.g. there is window.print() on the page so the print dialog is invoked.

I have found that somebody have/had the same problem but i dont think they solved it. http://stackoverflow.com/questions/226929/catching-window-pr int-from-swt-browser

I have an idea. The print dialog is a child window, isn't it? Is it possible to detect and delete all child windows of the main window with the browser?

Thanks a lot for any ideas.

Filip
Re: browser and javascript [message #529620 is a reply to message #529021] Mon, 26 April 2010 10:48 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2149
Registered: July 2009
Senior Member
Hi,

I don't think there's a general way to do this for all browser types. No
notification is sent when new windows/shells are created, and in the case of
the Browser embedding IE, swt is not involved at all in showing the dialog.
The only-cross browser possibility is if javascript provides a way to do
this, in which case you can Browser.execute() it.

If what you want is for window.print() to just print silently without asking
the user for print settings then this can be done when the Browser is
embedding Mozilla with a line like:

browser.execute(
"var prefs =
Components.classes[\"@mozilla.org/preferences-service;1\"].getService(Compon
ents.interfaces.nsIPrefBranch);" +
"prefs.setBoolPref(\"print.always_print_silent\", true);" +
"prefs.setBoolPref(\"print.show_print_progress\", false);");

The only problem with doing this is that these preference settings are
shared amongst all mozilla-based Browser instances, so they will also be
applied to other Browser controls that are not part of your app. Even
worse, these preference values will be persisted at shutdown time and will
be automatically used in future sessions. So the only use case where
changing preferences like this is suggested is if you have a stand-alone
application (since there won't be other Browser instances from other apps
being affected by your change), AND if you re-set these preference values to
their original values at shutdown time before they are written out (because
all eclipse-based apps share a common profile). For info on
getting/setting/clearing preference values like this see
http://www.mozilla.org/projects/embedding/embedapiref/embeda pi83.html .

Grant


"Filip" <filip.pekarek@gmail.com> wrote in message
news:hqpsoq$vll$1@build.eclipse.org...
> Hello,
> is there any way how to catch or disable some javascript functions on the
pages beying loaded in the browser. E.g. there is window.print() on the page
so the print dialog is invoked.
>
> I have found that somebody have/had the same problem but i dont think they
solved it.
http://stackoverflow.com/questions/226929/catching-window-pr int-from-swt-browser
>
> I have an idea. The print dialog is a child window, isn't it? Is it
possible to detect and delete all child windows of the main window with the
browser?
>
> Thanks a lot for any ideas.
>
> Filip
Previous Topic:Disable "Close Window" button on the title bar of a dialog
Next Topic:ImageData inconsistency?
Goto Forum:
  


Current Time: Sat Aug 30 16:29:21 EDT 2014

Powered by FUDForum. Page generated in 0.01821 seconds