按按钮关闭检票模式窗口

发布于 2024-10-17 00:36:07 字数 2755 浏览 4 评论 0原文

我想通过按模态窗口页面上的按钮来关闭模态窗口。它不起作用。我的模式窗口页面包含一个视频播放器。

我的代码是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我三岁 2024-10-24 00:36:07

这是一个示例脚本:

<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> 

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> 
一百个冬季 2024-10-24 00:36:07

您所需要做的就是在按钮代码中插入对 close 方法的调用。

要关闭窗口,有多个选项。静态方法 关闭(AjaxRequestTarget)< /a> 可用于从窗口内的 ajax 链接处理程序关闭窗口。


来源: 1.4.7 版本中 ModalWindow 的文档。

我看到您通过链接解决了问题,但您的帖子提到了一个按钮,所以我不知道链接解决方案是否只是一种解决方法,直到您得到更好的解决方案。另外,由于 close 是静态方法,因此您应该从类而不是实例中调用它。

All you need to do is insert a call to the close method in your button's code.

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.

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.

别理我 2024-10-24 00:36:07

您将在构造函数中获得 ModalWindow 窗口。

尝试

window.close(target);

you are getting ModalWindow window in your constructor.

Try

window.close(target);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文