Javascript Learning (3)-common methods (2)

Source: Internet
Author: User
1. Close the webpage in a browser with high compatibility. FireFox does not support (FireFox returns to the previous page). // FireFox does not support non-Windows. open () and other pop-up pages, you need to enter about: config in the address bar, and then the dom. change allow_script_to_close_windows to true to achieve... sy

1. Close the browser page with high compatibility

// Close the webpage. Firefox is not supported (Firefox returns to the previous page)
// FireFox non-window. open () and other pop-up pages, you need to enter about: config in the address bar, and then change dom. allow_script_to_close_windows to true to achieve the desired effect.
Function CloseWebPage (){
If (navigator. userAgent. indexOf ("MSIE")> 0 ){
If (navigator. userAgent. indexOf ("MSIE 6.0")> 0 ){
Window. opener = null; window. close ();
}
Else {
Window. open ('', '_ top'); window. top. close ();
}
}
Else if (navigator. userAgent. indexOf ("Firefox")> 0 ){
Window. history. go (-1 );
}
Else {
Window. close ();
}
}
// Close the webpage. Firefox is not supported (Firefox returns to the previous page)
// FireFox non-window. open () and other pop-up pages, you need to enter about: config in the address bar, and then change dom. allow_script_to_close_windows to true to achieve the desired effect.
Function CloseWebPage (){
If (navigator. userAgent. indexOf ("MSIE")> 0 ){
If (navigator. userAgent. indexOf ("MSIE 6.0")> 0 ){
Window. opener = null; window. close ();
}
Else {
Window. open ('', '_ top'); window. top. close ();
}
}
Else if (navigator. userAgent. indexOf ("Firefox")> 0 ){
Window. history. go (-1 );
}
Else {
Window. close ();
}
}
 

Ii. window. showModalDialog () Extension

// Open the ModalDialog subwindow and obtain the returned value
Function ModalDialogOpen (wUrl, wWidth, wHeight ){
If (window. showModalDialog! = Null) // IE judgment
{
Var returnvalue = window. showModalDialog (wUrl, "_ self", "dialogWidth:" + wWidth + "px; dialogHeight:" + wHeight + "px; status: no; help: no; scrolling = yes; scrollbars = yes; center = yes ");
If (! Returnvalue ){
Returnvalue = window. ReturnValue ;;
}
Return returnvalue;
}
Else {
This. returnAction = function (strResult ){
If (strResult! = Null)
Return strResult;
}
Window. open (wUrl, "", "width =" + wWidth + ", height =" + wHeight + ", menubar = no, toolbar = no, location = no, scrollbars = yes, status = no, modal = yes ");
}
}
// Close the ModalDialog subwindow and return the value
Function ModalDialogClose (val ){
If (window. showModalDialog! = Null) // IE judgment
{
If (navigator. userAgent. indexOf ("Chrome")> 0 ){
// Chrome support
Window. opener. ReturnValue = val;
} Else {
Parent. window. returnValue = val;
}
Window. close (); // firefox does not support
}
Else {
Window. opener. returnAction (val );
Top. close (); // both IE and FireFox support
}
}
 
// Open the ModalDialog subwindow and obtain the returned value
Function ModalDialogOpen (wUrl, wWidth, wHeight ){
If (window. showModalDialog! = Null) // IE judgment
{
Var returnvalue = window. showModalDialog (wUrl, "_ self", "dialogWidth:" + wWidth + "px; dialogHeight:" + wHeight + "px; status: no; help: no; scrolling = yes; scrollbars = yes; center = yes ");
If (! Returnvalue ){
Returnvalue = window. ReturnValue ;;
}
Return returnvalue;
}
Else {
This. returnAction = function (strResult ){
If (strResult! = Null)
Return strResult;
}
Window. open (wUrl, "", "width =" + wWidth + ", height =" + wHeight + ", menubar = no, toolbar = no, location = no, scrollbars = yes, status = no, modal = yes ");
}
}
// Close the ModalDialog subwindow and return the value
Function ModalDialogClose (val ){
If (window. showModalDialog! = Null) // IE judgment
{
If (navigator. userAgent. indexOf ("Chrome")> 0 ){
// Chrome support
Window. opener. ReturnValue = val;
} Else {
Parent. window. returnValue = val;
}
Window. close (); // firefox does not support
}
Else {
Window. opener. returnAction (val );
Top. close (); // both IE and FireFox support
}
}

 

From tu jiankai's column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.