- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 html 页面,其中有一个“关闭”按钮,单击该按钮应该关闭窗口。此 html 页面正在 Vaadin 对话框上加载。据我所知,Vaadin 负责使用 window.setClosable(true) 关闭对话框。但是,html 页面中的按钮也应该执行相同的操作。我如何启用此功能?
下面是代码:
myHelp.html:
<html>
<head>
</head>
<body>
.
.
<!-- This is at the footer right corner -->
<p class="myClass" align="right"><img src="images/iconclose.gif" width="50" height="10" border="0" onClick="window.close()" title="Close"></p>
.
.
</body>
</html>
Java 代码:
.
.
String link = "test/myHelp.html";
MenuItem menuItem = null;
if (link.contains("/test")) {
menuItem = menuBar.addItem("", new ExternalResource(StringUtil.append("/images/", images.get(i))), new Command() {
@Override
public void menuSelected(MenuItem selectedItem) {
final Window window = new Window(this.caption);
window.setClosable(true);
window.setWindowMode(WindowMode.NORMAL);
window.setModal(true);
window.setDraggable(true);
window.setResizable(false);
window.center();
window.addStyleName("abcdailog");
VerticalLayout layout = new VerticalLayout();
layout.setSizeFull();
layout.setSpacing(true);
layout.setMargin(true);
if (!CommonUtil.isEmpty(this.styleName)) {
window.addStyleName("abcStyle");
layout.setMargin(false);
}
if (!CommonUtil.isEmpty(link)) {
BrowserFrame browser = new BrowserFrame(null, new ExternalResource(this.link));
browser.setSizeFull();
layout.addComponent(browser);
} else {
verticalLayout.setSizeFull();
layout.addComponent(verticalLayout);
}
window.setContent(layout);
UI.getCurrent().addWindow(window);
}
}
});
.
.
.
发生的情况是 myHtml 被加载到新窗口中。作为一个 vaadin 窗口,一切都很好,但由于 html 在图像上有一个 window.close ,它应该工作但不起作用。我希望代码有助于更好地理解。
最佳答案
最简单的方法是在窗口底部添加一个 Vaadin 按钮。但是,如果这不是一个选择,有几种方法可以做到这一点,我想到的第一个方法(可能也是下一个最简单的方法)是添加 a callback JS function关闭窗口。
1) 自定义窗口实现:
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.JavaScript;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
public class MyHtmlWindow extends Window {
private static final String CLOSE_WINDOW_FUNCTION = "closeWindow";
public MyHtmlWindow() {
// some window configuration
setModal(true);
setClosable(true);
setResizable(false);
}
public void show(UI ui) {
// add some HTML content in a label including the call to the closeWindow() JS function
setContent(new Label("<html>\n" +
"<button type=\"button\" onClick=\"" + CLOSE_WINDOW_FUNCTION + "();\">Close</button>\n" +
"<script>\n", ContentMode.HTML));
// add a JS function to close the window
JavaScript.getCurrent().addFunction(CLOSE_WINDOW_FUNCTION, arguments -> this.close());
// show the window
ui.addWindow(this);
}
@Override
public void close() {
// call super so everything gets cleaned up nicely
super.close();
// remove previously added function
JavaScript.getCurrent().removeFunction(CLOSE_WINDOW_FUNCTION);
}
}
2)用法:
public class MyVaadinUI extends UI {
@Override
protected void init(VaadinRequest request) {
new MyHtmlWindow().show(this);
}
}
3) 结果:
附注:欢迎提出改进建议
关于javascript - 如何在 vaadin 对话框中启用 javascript window.close()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38830141/
我想知道如何首先检测 Javascript 是否启用/禁用。在此站点上禁用 javascript 表明 stackoverflow 使用了称为标签的东西。 这是标准的做法吗?它适用于所有浏览器吗?它不
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How to enable PHP short tags ? Enable short open tags
在 VSTS (Azure DevOps) 上拥有私有(private)存储库我尝试通过将以下内容添加到 .csproj 文件来启用 SourceLink:https://github.com/dot
我创建了一个 wx.Frame(我们称之为 mainFrame)。该框架上包含一个按钮,当单击该按钮时,会创建一个新框架(我们称之为 childFrame)。 我想知道如何在创建 childFrame
当我禁用 WPF 中的控件时,比如说一个菜单项 MenuItem aMenuItem = ... aMenuItem.IsEnabled = false; MenuItem 中的文本仍然处于事件状态,
我想在我的 nginx 服务器上启用 gzip 压缩。 nginx.conf 文件在这里: http { # Enable Gzip server { location ~* \.(?
我正在使用免费的 heroku 附加 PG 备份并遵循这些 instructions .我找到了安装应用程序的命令:heroku addons:add pgbackups:auto-week。但是我想
我想知道脚本是否可以使用某种切换按钮启用/禁用页面上的所有输入元素。 我用谷歌搜索了它,但除了这个之外没有发现任何有用的东西: http://www.codetoad.com/javascript/e
在我的 php 文件中,我想使用 jQuery Datepicker。 当我的文件加载时,我创建了禁用的日期选择器。 然后,当我的 php 文件(它是一个表单)中的一个特殊字段被填充时,我想启用日期选
我有一个按钮,如下所示: RadButton lnkAdd = new RadButton(); lnkAdd.ID = "BtnAdd"; lnkAdd.CommandName = RadGrid.
public static void ToggleTaskManager(string keyValue) { RegistryKey objRegistryK
我正在 Azure 中使用事件网格订阅,该订阅在创建 Blob 时触发。然而,我们有很多文件进入这个 blob,比如说 1000 多个。 如果我发现任何文件有任何错误,我想做的是禁用事件订阅。 最佳答
我的网站上有几个使用 HTML5 contentEditable 属性的 div。目标是让用户能够开始编写日记条目,并将保存按钮从禁用更改为启用。 这是我目前拥有的 HTML: Write
我有一个范围输入,其定义如下: @Html.LabelFor(m => Model.Quality, Resources.CompressionQuality) 和一个下拉菜单: @Html.Lab
我正在尝试创建一个启用/禁用按钮的下拉菜单,并且我正在关注此 example 但它已经有 4 年历史了,而且该功能似乎无法在我的 xhtml 页面上运行。 任何帮助都将被适当 最佳答案 这是一个现场演
我正在 Azure 中使用事件网格订阅,该订阅在创建 Blob 时触发。然而,我们有很多文件进入这个 blob,比如说 1000 多个。 如果我发现任何文件有任何错误,我想做的是禁用事件订阅。 最佳答
我在这里遇到一个非常奇怪的情况:我编写了一个应用程序,除其他外,将连接的代理从打开切换到关闭,反之亦然。通过更改注册表中的值来完成此操作: public void SetUpProxy(string
我需要调整一堆 PVC 的大小。似乎最简单的方法是通过ExpandPersistentVolumes 功能。但是我无法获得配置合作。 ExpandPersistentVolumes feature g
如果我的TextField为空,则应禁用该按钮,并且该按钮的textColor和borderColor应该为灰色。但是,启用按钮后,颜色应为蓝色。 更改textColor很容易: button.Set
您好,我的问题是:我无法从另一个类启用表单的按钮。我的表单类是 public class FileSending { //Function for enabling the button
我是一名优秀的程序员,十分优秀!