浏览器的渲染模式是否有可能动态地从标准变为怪异
假设您有一个以浏览器的标准呈现模式呈现的页面。假设页面上有一个按钮,单击该按钮会下载一组外部 CSS 和 JavaScript 文件并创建一些 DOM 元素。
按下按钮、下载新的 CSS 和 JavaScript 并创建新的 DOM 后,页面的渲染模式是否有可能从标准变为怪异?
Suppose that you have a page that renders in browser's standard rendering mode. Suppose that there is a button on the page that, when clicked, downloads a set of external CSS and JavaScript files and creates some DOM elements.
Is it possible that after the button is pressed and new CSS and JavaScript is downloaded and new DOM created, that the rendering mode for the page changes from standard to quirks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答:我不知道。
长答案:您也许能够利用浏览器特定的“功能”并说服浏览器从标准更改为怪癖,但这可能会涉及一些令人讨厌的黑客行为和无法维护的编码实践。 W3C 有一个名为
DOMImplementation
的接口 (链接到规范)向 DOM2 添加了一些文档级功能,但至于它们的效果如何,我不能说。然而,这个答案的关键点是,您应该首先明确为什么需要怪癖模式。理想情况下,您应该创建新的 DOM 元素以与标准模式兼容并完全避免整个混乱。考虑到怪异模式在不同浏览器之间可能存在很大差异,因此最好的选择是以标准为目标并根据具体情况处理不一致的情况。
Short answer: I have no idea.
Long answer: You might be able to take advantage of browser-specific "features" and convince the browser to change from standards to quirks, but it would likely involve some nasty hacks and unmaintainable coding practices. The W3C has an interface called
DOMImplementation
(link to specification) that adds some document-level functions to DOM2, but as far as how effective they are I can't say.However, the key point of this answer is that you should question exactly why you need quirks mode in the first place. Ideally, you should create your new DOM elements to be compatible with standards mode and avoid the whole mess altogether. Considering that quirks mode can vary greatly between browsers, your best bet is to target the standard and handle inconsistencies on a case-by-case basis.