我搜索了类似的主题,在jsf应用程序中添加了全屏选项。我试图将"https://stackoverflow.com/a/11820717/1194553“和"https://stackoverflow.com/a/7525760/1194553”解决方案添加到jsf应用程序的jsp文件中,例如;
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Making Full Screen</title>
<script type="text/javascript">
function cancelFullScreen(el) {
var requestMethod = el.cancelFullScreen||el.webkitCancelFullScreen||el.mozCancelFullScreen||el.exitFullscreen;
if (requestMethod) { // cancel full screen.
requestMethod.call(el);
} else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}
function requestFullScreen(el) {
// Supports most browsers and their versions.
var requestMethod = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
if (requestMethod) { // Native full screen.
requestMethod.call(el);
} else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
return false;
}
</script>
</head>
<body>
<f:view>
<h:form id="mainForm">
<div>
<h:commandButton id="topBtn" styleClass="topMenuItem topMenuItem" image="images/common/fullScrUfa.png" onmouseover="this.src='images/common/fullScrFa.png'" onmouseout="this.src='images/common/fullScrUfa.png'" onclick="requestFullScreen(document.body);"></h:commandButton>
</div>
</h:form>
</f:view>
</body>
</html>当我运行该项目并单击id为"topBtn“的按钮时,我希望使浏览器视图显示在全屏上。我尝试了chrome vs.27.0.1453.116和资源管理器10。
但是,当我按下按钮时,视图将以全屏模式显示,并立即返回正常模式,而无需等待任何单击或其他操作。虽然,这个动作发生在不到一秒钟,但我可以意识到当我仔细看。
我该如何解决这个问题?
发布于 2013-12-31 16:43:23
您需要像这样添加return false;:
onclick="requestFullScreen(document.body);return false;"若要停止单击的传播,请停止表单提交。
不相关:
如果不使用任何JSF功能,则不需要使用<h:commandButton />。一个简单的<input type="button" onclick="..." />。这只是一个稍微更好的表现的问题。您可以在JSF中使用普通HTML。这对于<h:panelGroup />来说也是一样的,我不会滥用它们,如果没有必要,我将使用<span />或<div />
https://stackoverflow.com/questions/20842884
复制相似问题