显示“启用JavaScript”仅在禁用JavaScript时才会显示消息 [英] Display "Enable JavaScript" message only when JavaScript is disabled
问题描述
我希望在禁用JavaScript的情况下向用户显示请启用JavaScript的消息。我想要那条消息,禁用JavaScript时不会显示任何其他内容。
I want to display to the user a message that says "please enable JavaScript" in the case that JavaScript is disabled. I want that message, and nothing else to be displayed when JavaScript is disabled.
所以,为此,我可以将消息放入DOM并隐藏所有其他元素显示:无。然后在JavaScript中,我可以将消息设置为隐藏显示并显示所有其他元素。
So, to do this, I can put the message in the DOM and hide all other elements with display:none. Then in JavaScript I can set the message to display hidden and show all other elements.
但是我用这种方法得到了一个闪烁。在隐藏之前,错误消息会显示一段时间(特别是在移动浏览器上)。
But I get a flicker with this approach. The error message shows up for a while (especially on mobile browsers) before it gets hidden.
如何最小化显示错误消息的时间?
How can I minimize the time the error message is displayed for?
推荐答案
您正在寻找 < noscript>
标签。
You're looking for the <noscript>
tag.
这篇关于显示“启用JavaScript”仅在禁用JavaScript时才会显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!