按按钮关闭检票模式窗口
我想通过按模态窗口页面上的按钮来关闭模态窗口。它不起作用。我的模式窗口页面包含一个视频播放器。
我的代码是:
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();"), ";"));
}
}
这是 HTML:
<div wicket:id="videoDiv">
<div id="movieDiv"></div>
<input type="button" wicket:id="close" />
</div>
注释掉的代码行是我的测试。任何信息都会对我非常有帮助。谢谢。
编辑:
我用这段代码解决了我的问题:
add(new AjaxLink("close") {
public void onClick(AjaxRequestTarget target) {
window.close(target);
}
});
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:
<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);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个示例脚本:
Here is an example script:
您所需要做的就是在按钮代码中插入对
close
方法的调用。来源: 1.4.7 版本中
ModalWindow
的文档。我看到您通过链接解决了问题,但您的帖子提到了一个按钮,所以我不知道链接解决方案是否只是一种解决方法,直到您得到更好的解决方案。另外,由于
close
是静态方法,因此您应该从类而不是实例中调用它。All you need to do is insert a call to the
close
method in your button's code.Source: documentation of
ModalWindow
in the 1.4.7 release.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.您将在构造函数中获得 ModalWindow 窗口。
尝试
you are getting ModalWindow window in your constructor.
Try