java 按下按钮关闭检票口模式窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4944728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Close wicket modal window by pressing a button
提问by Tapas Bose
I want to close a modal window by pressing a button residing on the modal window page. It is not working. My modal window page contains a video player.
我想通过按下位于模态窗口页面上的按钮来关闭模态窗口。它不工作。我的模态窗口页面包含一个视频播放器。
My code is:
我的代码是:
public class PlayVideoWindow extends WebPage {
public PlayVideoWindow(final Page modalWindowPage, final ModalWindow window, final String itemId) {
final String xmlFilePath = ((WebApplication) getApplication()).getServletContext().getRealPath("/resources/video/xml/video.xml");
String filename = null;
try {
filename = WebVideo.getVideo(itemId, xmlFilePath);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
WebMarkupContainer videoContainer = new WebMarkupContainer("videoDiv");
add(videoContainer);
add(HeaderContributor.forJavaScript("resources/video/js/swfobject.js"));
final String script = "var swfVersionStr = '10.0.0';"
+ "var xiSwfUrlStr = 'playerProductInstall.swf';"
+ "var flashvars = {};"
+ "flashvars.filename = '"+ filename +"'" +";"
+ "var params = {};"
+ "params.wmode = 'transparent';"
+ "params.quality = 'high';"
+ "params.allowscriptaccess = 'always';"
+ "params.allowfullscreen = 'true';"
+ "params.allownetworking = 'all';"
+ "var attributes = {};"
+ "attributes.id = 'Player';"
+ "attributes.name = 'Player';"
+ "attributes.align = 'left';"
+ "swfobject.embedSWF('/jtrac/resources/video/swf/Player.swf', 'movieDiv', '320', '320', swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);"
+ "swfobject.createCSS('#flashContent', 'display:block;text-align:left;');";
add(new AbstractBehavior() {
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.renderOnLoadJavascript(script);
}
});
//videoContainer.add(new AjaxButton("close") {
// protected void onSubmit(final AjaxRequestTarget target, final Form form) {
// PlayVideoWindow.this.close(target);
//}
//});
//Button closeButton;
//videoContainer.add(closeButton = new Button("close"));
//closeButton.add(new AttributeAppender("onclick", new Model("window.close();"), ";"));
}
}
And here's the HTML:
这是 HTML:
<div wicket:id="videoDiv">
<div id="movieDiv"></div>
<input type="button" wicket:id="close" />
</div>
The commented-out lines of code are my tests. Any information will be very helpful to me. Thank you.
注释掉的代码行是我的测试。任何信息都会对我很有帮助。谢谢你。
EDIT:
I solved my problem with this code:
编辑:
我用这段代码解决了我的问题:
add(new AjaxLink("close") {
public void onClick(AjaxRequestTarget target) {
window.close(target);
}
});
采纳答案by Pops
All you need to do is insert a call to the close
method in your button's code.
您需要做的就是close
在按钮的代码中插入对该方法的调用。
To close the window there are multiple options. Static method
close(AjaxRequestTarget)
can be used to close the window from a handler of ajax link inside the window.
要关闭窗口,有多种选择。静态方法
close(AjaxRequestTarget)
可用于从窗口内的 ajax 链接处理程序关闭窗口。
Source: documentation of ModalWindow
in the 1.4.7 release.
来源:1.4.7 版本中的文档ModalWindow
。
I see that you solved your problem with a link, but your post mentioned a button, so I don't know if the link solution was just a workaround until you got something better. Also, since close
is a static method, you should call it from the class, not an instance.
我看到你用链接解决了你的问题,但你的帖子提到了一个按钮,所以我不知道链接解决方案是否只是一种解决方法,直到你得到更好的东西。此外,由于close
是静态方法,您应该从类中调用它,而不是从实例中调用它。
回答by allojo
Here is an example script:
这是一个示例脚本:
<script type="text/javascript">
if (top != self) {
var wicket = top.Wicket;
if (wicket && wicket.Window) {
var modal = wicket.Window.get();
if (modal) {
modal.close();
}
}
top.location.href = location.href;
}
</script>
回答by code_fish
you are getting ModalWindow window in your constructor.
您正在构造函数中获取 ModalWindow 窗口。
Try
尝试
window.close(target);