在 stackoverflow 上也检查了很多信息,比如这里How do I call a JavaScript function on page load?
但我仍然在加载时遇到问题。我有这个:
代码在这里:http: //jsbin.com/agopuv/2/edit
编辑:添加HTML+JS
代码这是js
代码:
function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreen && !document.webkitIsFullScreen)) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
$(document).on('pageinit', function () {
setTimeout(toggleFullScreen,1000);
});
和Html
代码:
<input type="button" id="button" value="click to toggle" onclick="toggleFullScreen()">
它实际上只在按下按钮时才起作用,但我没有以任何方式成功地在页面加载时触发该功能。
对此有何建议?谢谢。