public native void printFrame() /*-{
$wnd.print();
}-*/;
But this prints the whole page, and I want to print the contents of one
of iframes only. So before printing I am setting focus on the iframe I
want to print, and then I am calling the above function, like this:
frmDiaInfo.setFocus(true);
printFrame();
But this causes the following exception:
com.google.gwt.core.client.JavaScriptException: JavaScript TypeError
exception: elem.focus is not a function
Is this a bug?
Hope this helps.
But what I wanted to achieve is to make browser open a standard print
dialog - which would be normally achieved in ordinary JavaScript by
using window.print() function.
I was experimenting for a while with JavaScript in a native method and
the results are strange. Say, I want to check whether the standard
window object which is referred to in GWT as $wnd knows anything about
my iframes at all. I have used the following code:
var x = $wnd.frames;
$wnd.alert(x.length);
Which informs me that $wnd has 3 frames. I don't use any frames on that
page, but I use 2 iframes, and the third may be added by GWT itself.
Fine.
But now I am trying to find out some information about those iframes,
like so:
var x = $wnd.frames[1].name - produces an empty string perhaps, the
alert box is empty
var x = $wnd.frames[1].id and the same for src produces 'undefined'.
Attempts like
$wnd.frames[1].focus();
$wnd.frames[1].print();
or
$wnd.frames[1].focus();
$wnd.print();
also do not produce the desired effect.
I have no way to assign any name to the Frame widget. I do not see how
I could print it contents using the standard browser (and OS)
facilities - something I would be able to do in basic JavaScript. So
far my conclusion is that GWT is too young at the moment.
Of course the framework is too young, many requests have been made to
improve it already. It's been out for what, 3 weeks?
Perhaps if you phrased this as a feature request (which is what this
is) and proposed a patch you will get some movement and ultimately
satisfaction.
Geoff
And of course you are right. GWT is fascinating, and it only the lack
of knowledge of how to communicate a feature request makes me producing
this kind of statements.
Thanks for the Spindle, by the way!
It's possible that not all browsers allow IFrames to receive focus.
We'll take a look at this. Meanwhile, do you need to focus the IFrame
to print it? You might try this:
private native void printFrame(Element e) /*-{
e.contentWindow.print();
}-*/;
printFrame(frmDialInfo.getElement());
Scott
And thanks for the compliment!
Geoff
This works like magic with Firefox, but IE6 still prints the whole
page...
Thanks a lot for your help guys!
Alex