Home >Web Front-end >JS Tutorial >Use js to determine whether the page is loaded and implement the code_Basic knowledge

Use js to determine whether the page is loaded and implement the code_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:46:471288browse

Use the document.onreadystatechange method to monitor state changes,
and then use document.readyState == "complete" to determine whether the loading is complete
The code is as follows :

Copy code The code is as follows:

document.onreadystatechange = subSomething; //Execute this method when the page loading status changes.
function subSomething()
{
if(document.readyState == “complete”) //When the page is loaded
myform.submit(); //Form submission
}

Five states of page loading readyState
The original text is as follows:
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire response received.
3: (Interactive) the response is being parsed.
4: (Completed) the response has been parsed, is ready for harvesting.

is translated into Chinese as :
0 - (not initialized) the send() method has not been called yet
1 - (Loading) The send() method has been called and the request is being sent
2 - (Loading completed) The send() method has been executed and all response content has been received
3 - (Interaction) is being Parse the response content
4 - (Complete) The response content is parsed and can be called on the client
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn