【发布时间】:2014-06-14 14:51:37
【问题描述】:
我知道有几个关于这个问题的主题,但我找不到适合我的解决方案。
所以这是我的问题:
我的网站是响应式的,并在从移动设备加载时显示一个信息框。此信息框显示了如何将网站保存为 WebApp 的教程链接。当用户从 WebApp 加载网站时,应该隐藏信息框。
这是我正在使用的代码(不工作):
<script type="text/javascript">
if (window.navigator.standalone == true) {
document.getElementById('alertbox')[0].style.display = 'none !important';
}
</script>
信息框的 ID 为“alertbox”:
<div id="alertbox" class="alert alert-info visible-phone">
<button type="button" class="close" data-dismiss="alert">×</button>
This website supports iOS-WebApps. Learn more <a href="/guides/ios-webapp">how to save this website as WebApp</a>.
</div>
“!important”标签是必需的,因为我正在使用 Twitter 的 BootStrap,他们已经将子属性(显示)定义为 !important。
提前致谢。
【问题讨论】:
-
当您尝试更改其
css时,您的javascript 是否位于页面末尾以确保alertbox在DOM中可用?或者,如果您已经包含jQuery,则可以使用一些DOM ready回调。 -
感谢您的提示,在包含 bootstrap.js 文件后,我将脚本从 移到了 html 的末尾,但它仍然不起作用。您能否解释一下“DOM 就绪回调”是什么意思?我对 JavaScript 完全陌生。
标签: javascript ios css web-applications detection