如何在GWT中访问IFRAME之外的代码?
我有一个html,比如说a.html。我在IFRAME中调用A.html中的A.html如何在GWT中访问IFRAME之外的代码?,gwt,iframe,Gwt,Iframe,我有一个html,比如说a.html。我在IFRAME中调用A.html中的A.html A.html <html> ..... <IFRAME> A.html (same domain, etc as A.html) </IFRAME> </html> A.html ..... A.html(与A.html相同的域等) 这是一个GWT应用程序。这个IFRAME是一个弹出窗口,当用户关闭(单击关闭按钮)这个弹出窗口时(正如上面所
A.html
<html>
.....
<IFRAME>
A.html (same domain, etc as A.html)
</IFRAME>
</html>
A.html
.....
A.html(与A.html相同的域等)
这是一个GWT应用程序。这个IFRAME是一个弹出窗口,当用户关闭(单击关闭按钮)这个弹出窗口时(正如上面所示,它也正在加载a.html),我想
触发一个事件以在外部A.html上显示一些消息,这意味着我需要访问IFRAME之外的代码。我怎样才能做到这一点
谢谢因为您的iframe内容是从同一个域加载的,所以您可以在包含页面上调用javascript函数。我假设您正在询问从GWT调用iframe之外的代码。如果是这样,那么您可以使用JSNI 例如,给定JSNI方法:
private final native void postClosedEvent()
/*-{
$wnd.functionDefinedOutside();
}-*/
您可以在GWT ClickHandler中调用该方法:
closeButton.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent e)
{
postClosedEvent()
}
});
这假设在包含页面中使用javascript定义了一个函数,例如:
<script type="text/javascript">
var functionDefinedOutside =
function()
{
alert("GOT MESSAGE FROM iframe");
};
</script>
外部定义的var函数=
函数()
{
警报(“从iframe获取消息”);
};
注意:如果iframe内容是从不同的域加载的,则可以使用实现相同的结果。GWT模块中的iframe定义为:
<iframe src="/temp.jsp"></iframe>
IFRAME中的JSP:temp.JSP
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>temp</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
</style>
</head>
<body>
<div id="content">
Holla commo estas from the iframe!
</div>
<script type="text/javascript">
window.alert("inside iframe");
window.parent.mt("passing a value to a parent!!!");
</script>
</body>
</html>
临时雇员
伊夫拉姆,大家好!
窗口警报(“内部iframe”);
mt(“将值传递给父项!!!”;
如何定义函数外部定义?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>temp</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
</style>
</head>
<body>
<div id="content">
Holla commo estas from the iframe!
</div>
<script type="text/javascript">
window.alert("inside iframe");
window.parent.mt("passing a value to a parent!!!");
</script>
</body>
</html>