After the page is loaded, a method of js Code is automatically executed. js Code
1. Use onload in the body:
<body onload="myfunction()">
2. Use window. onload in the script:
<Script type = "text/javascript"> function myfun () {alert ("this window. onload ");}/* use window. onload calls myfun () */window. onload = myfun; // No parentheses </script>
In the following example, the background color of id_1 is changed after the page is loaded.
<Script language = "javascript"> function myfun () {document. getElementById ("id_1 "). style. background = "#000"; // change the background color} // use js to automatically execute a method after loading a page/* use window. onload calls myfun () */window. onload = myfun; // No parentheses </script>
Programming Enables automatic execution of a piece of js Code each time a webpage is opened
<Html>
<Head>
<Style type = "text/css">
. Box {border: 0}
</Style>
<Script language = "javascript">
Var x = 100;
Var timer;
Function startTime ()
{
Timer = setInterval ("Time ()", 1000 );
}
Function Time ()
{
Var time = new Date ();
Var year = time. getYear ();
Var month = time. getMonth ();
Var date = time. getDate ();
Var day = time. getDay ();
Var hours = time. getHours ();
Var minutes = time. getMinutes ();
Var seconds = time. getSeconds ();
Document.form1.txt Time. value = "current date:" + year + "year" + (month + 1) + "month" + date + "day and week" + day + "Current Time: "+ times (hours) +": "+ times (minutes) +": "+ times (seconds) + "";
}
Function times (time)
{
If (time <10)
{
Time = "0" + time;
}
Return time;
}
</Script>
</Head>
<Body onLoad = "startTime ()">
<Form name = "form1"> <input class = "box" name = "txtTime" size = "50"> </form>
</Body>
</Html>
This is the Javascript script automatically executed when the webpage is opened. This script is used to display the current system time. When the webpage is opened, this script is called in the onLoad event of the <body> attribute, this is written in the HTML language, and it is not difficult to learn it. I guess I will read it when I read it.
How to load the page, and then execute js onload as if it was executed together by js, it means that the page has been loaded and will not be circled, and then execute js to help
<Script>
<! --
Document. onreadystatechange = subSomething; // This method is executed when the page loading status changes.
Function subSomething ()
{
If (document. readyState = "complete" & window. parent. frames ["framework name" 2.16.doc ument. readyState = "complete") // enters
Myform. submit (); // This is your operation
}
// -->
</Script>
--------------
Then add an IF condition:
Window. parent. frames ["mainFrame" mirror.doc ument. readyState = "complete"
The code above has been modified.
--------------
Add a name without name. You can still write it without name. It has no effect.
Alternatively, you can write as follows:
Too many parent.frames.framework name .doc ument .....
--------------
P... the if condition is added. What is the top of your loop? As you do. As long as the first frame is loaded, it will be executed directly. Where can we loop to the next frame.
Add the frame to be judged to the if statement.