是否可以使用JavaScript更改document.readyState? [英] Is it possible to change document.readyState with JavaScript?

查看:53
本文介绍了是否可以使用JavaScript更改document.readyState?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过网站上的iframe加载HTML.仅在父文档完成加载后,正在加载的HTML应该等待加载某些内容( document.readyState =='interactive'|| document.readyState =='complete').问题是在父文档完成加载后,HTML 内容被手动加载到 iframe 中.

I'm loading HTML via an iframe on a site. The HTML being loaded is supposed to wait to load certain content only after the parent document has finished loading (document.readyState == 'interactive' || document.readyState == 'complete'). The problem is that the HTML content is manually loaded into the iframe well after the parent document has finished loading.

有什么方法可以欺骗父文档的readyState,以验证加载的HTML内容没有过早呈现?

Is there any way to spoof the readyState of the parent document in order to verify the loaded HTML content isn't rendering prematurely?

推荐答案

这是对您的问题的部分答案:这里有两件事:文档对象模型 Javascript . DOM 是浏览器的状态,其中存储了所有必需的信息以显示此页面的查看器. Javascript 是用于查询/操作状态(阅读 DOM )的工具.

This is a partial answer to your question: There are two different things here: Document Object Model and Javascript. DOM is the state of the browser that stores all required information to display the viewer of this page. Javascript is the tool used to query/manipulate state (read DOM).

DOM通知Javascript处于就绪状态更改,并且这只是一种方式,因为此属性为

DOM notifies Javascript of readystate change and this is only one-way as this property is read-only. Short answer to your question is "No", you can not alter readyState property using Javascript.

要亲自查看,您可以打开控制台(Firebug,Chrome开发工具)等,并在控制台中输入:

To see this for yourself, you can pull up a console(Firebug, Chrome dev tools) etc. and in the console type:

typeof document.readyState // "String"
document.readyState // "complete"
document.readyState = "hello world" // "hello world"
document.readyState // if you expected it to show "hello world" it still shows "complete"

这篇关于是否可以使用JavaScript更改document.readyState?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆