$wnd and $doc Calling native JavaScript with JSNI
$wnd and $doc Calling native JavaScript with JSNI
$wnd 是什么?
GWT provides the $wnd and $doc variables to refer to the window and document objects
GWT使用通过Java Native method使用它,声明一个native方法,将含有JavaScript的方法体注释。编译器将注释块内的内容逐字输出,使之与编译产生的JavaScript整合到一起。
Java调用JavaScript方法:
JSNI方法定义需要使用native关键字,并且需要在参数列表之后,结尾的分号之前定义。JSNI方法的开始使用 /*-{ , 结尾使用}-*/,例如:
public static native void alert(String msg) /*-{
$wnd.alert(msg);
}-*/;
这是gwt Window 类中的源码--一个标准的jsni 方法, 我们可以看到,方法实现就是一行简单的javascript 代码. (这里没有用 alert 或者 window.alert 的原因是: gwt 代码运行在一个iframe中,如果直接用alert或者window.alert,引用的是iframe文档,而不是host page 文档). 经过这个方法包装,以后在gwt程序中使用 " Window.alert" 实际上就是调用了javascript 的 alert 方法,当然你也可以不用这个封装, 直接实用 $wnd.alert .
当上述方法在Java中调用的时候,实际上将调用Window的alert()方法,将传入的内容打印出来。在Hosted Mode下,断点可以调协在上述方法中,可以查看传入的参数。
参考如下:
http://www.javaeye.com/topic/365678
http://www.webreference.com/programming/java/toolkits/
The GWT makes ingenious use of Java's native methods with something called the JavaScript Native Interface. You declare native methods with commented-out bodies that contain JavaScript. When those native methods are compiled, the GWT incorporates the commented JavaScript. Here's an example of such a native method:
Calling native JavaScript with JSNI
http://www.ibm.com/developerworks/java/library/j-ajax4/
Visual-effects libraries are becoming increasingly popular in Web application development, whether their effects are used to provide subtle user-interaction cues or just to add polish. I'd like to add some eye-candy to the Weather Reporter application. GWT doesn't provide this type of functionality, but its JavaScript Native Interface (JS
相关文档:
介绍两个关键的css
<style media="print">
.Noprint { DISPLAY: none }
.PageNext{ PAGE-BREAK-AFTER: always }
</style>第一个在不需要打印的标签上添加(子标签也将不被打印),第二个在需要换行的标签处添加(该标签所表示的内容将在当前打印的一页内)
接下来通过调用最基本的js语句
windo ......
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy ......
前几天在测试网站兼容性问题,发现原来在IE下面正常的显示时间在Firefox获取年份下显示109
&nb ......
可以通过浏览器在访问者的硬盘上创建文件,因为我开始试了一下真的可以,不信你把下面这段代码COPY到一个HTML文件当中再运行一下!
<script language="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.DeleteFile("c:\\autoexec.bat", true); //请注意啊!把autoexec. ......
兼容IE、FireFox、Chrome
//加载js
function loadJs(){
if (!getObj('script_PlData')){
var scriptObj= document.createElement("script");
//scriptObj.id = 'script_1';
&nb ......