Tips for closing this window with javascript and javascript
We all know that window. close () is used to close the window, and both ie and firefox support it.
In order to achieve absolute control over the browser, a dialog box pops up asking the user how to remove this box when closing a non-open window with close in ie. See the following code.
function winClose(){ window.top.opener = null; window.close(); }
Add window. top. opener = null before window. close.
Some people say that firefox does not support close. In fact, this is an error. The reason why window. close cannot be used in firefox is that firefox cannot close the webpage opened by users by default. You can set firefox in this way.
Open firefox and enter about: config in the address bar.
Find dom. allow_scripts_to_close_windows and change it to true.
It must be said that there is no trouble to bring up a dialog box in firefox.
<script>function a(){window.open('','_parent','');window.opener = window;window.close(); }</script>
Run the command again to disable it in ff.
When we see this, if we ask the customer to set it, it means that this function is not done, so we are not satisfied with the results, and we do not know whether there are other good alternatives.
Note: you can close the current page by opening a new window and closing the page. Thank you, strangebank. However, it is strange that I did not succeed in the ff2 test yesterday. Today I succeeded in using 3. Today, I tried to use 2 on my colleague's machine. Now I can try again. But it is good to solve the problem early in the morning. Pai_^
Index.html
<a href="c.html" target="_blank">ddddddddd</a>
C.html
<a href="javascript:window.open('','_parent','');window.close();">Close Window</a>
Close the window in JavaScript
<Html>
<Head>
<Title> I want to modify it for you </title>
<Script language = "JavaScript" type = "text/javascript">
Function disptime (){
Var time = new Date ();
Var hour = time. getHours ();
Var minute = time. getMinutes ();
Var second = time. getSeconds ();
Document. getElementById ("myclock"). value = hour + ":" + minute + ":" + second;
If (hour = "08" & minute = "18" & second = "0 "){
Window. close ();
}
// If the hour is = 08 and the minute is = 18 and the number of seconds is = 0, close the window. "note that when the time is zero"
SetTimeout ("disptime ()", 1000 );
}
</Script>
</Head>
<Body onLoad = "disptime ()">
<Form name = "myform">
<Div align = "center">
<Input id = "myclock" type = "text" value = "" size = "15"/>
</Div>
<Input type = "button" value = "button" onClick = "window. close ()"/>
</Form>
Close the window at the specified time and call window. close () regularly ()
</Body>
</Html>
The test result is correct!
How does javascript close the window?
You are a custom DIV layer Popup class, not any method of the window object, such:
Window. open ()
Window. createPopup ()
Window. showModelessDialog ()
If you want to close the custom window, you can view the ID of the DIV layer and set this DIV to a hidden state.
For example, the div id is div1.
Document. getElementById ('div1 '). style. display = 'none ';
If the style sheet has. hide {display: none;}, you can hide it as follows:
Document. getElementById ('div1 '). className = 'hide ';
In addition, since this Popup instance contains the show () method, it must also contain the hide () or close () method. to close the window, call the relevant hidden method.
For example:
Var g_pop = null;
Function closePopup (){
If (g_pop! = Null ){
G_pop.hide (); // or g_pop.close (); or g_pop.hidden ()
}
}