我在 HTML 页面中有一个嵌入式 iframe。iframe 中的页面是使用 GWT 创建的。
GWT 程序有静态变量,这是我公开的一个静态方法,因此可以从外部调用它。在 GWT 程序中,有一个计时器每 10 秒检查一次静态变量。
外部 HTML 页面有一个按钮,当按下按钮时,javascript 代码会调用我的 gwt 程序中的静态方法(即在 HTML 中的 iframe 中)
我可以看到调用了GWT静态方法(里面有一个js警报调用)。但是每 10 秒运行一次并检查静态变量(在静态方法中更改)的函数报告其值没有更改。
HTML 片段
<script type="text/javascript" src="/war/mygwtproject/mygwtproject.nocache.js">
<iframe id="feeds_frame" src="../root/war/mygwtproject.html" width="190" height="650" frameborder="1">
</iframe>
function toggleDrawingFeeds()
{
myGwtStaticMethod();
}
GWT 代码
static boolean wasInitiated = false;
public static void myFunc()
{
MyGwt.wasInitiated = true;
alert(MyGwt.wasInitiated);
}
public void setTimer()
{
Timer t = new Timer()
{
public void run()
{
alert(MyGwt.wasInitiated);
if (MyGwt.wasInitiated)
{
//do something
}
else
{
//do something else
}
}
};
// Schedule the timer to run once in 5 seconds.
t.scheduleRepeating(10000);
}
public static native void exportStaticMethod() /*-{
$wnd.myGwtStaticMethod = $entry(@myPackage.MyEntryPoint::myFunc());
}-*/;
谢谢,约阿夫