问题
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.
Is there any way to spoof the readyState of the parent document in order to verify the loaded HTML content isn't rendering prematurely?
回答1:
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 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.
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"
来源:https://stackoverflow.com/questions/21947982/is-it-possible-to-change-document-readystate-with-javascript