Parse js to get the getParent method of the parent window link and various window opening Methods _ basic knowledge

Source: Internet
Author: User
This article provides a detailed analysis of the getParent method for obtaining the parent window link in js and various window opening methods. For more information, see The Code is as follows:


// Open the modal window
Function dialog (obj ){
If (obj. url = undefined | obj. url = null ){
Throw new Error ("please set obj. url ");
}
Var url = obj. url;
If (url. indexOf ("? ")! =-1 ){
Url = url + "& r _ =" + Math. random ();
} Else {
Url = url + "? R _ = "+ Math. random ();
}
// Alert (obj. width + "," + obj. height + "," + obj. top + "," + obj. left );
Var w;
If (! Obj. width ){
W = screen. width/2;
} Else {
W = parseInt (obj. width );
}
Var h;
If (! Obj. height ){
H = 500;
} Else {
H = parseInt (obj. height );
}
Var t;
If (! Obj. top ){
T = 50;
} Else {
T = parseInt (obj. top );
}
Var l;
If (! Obj. left ){
L = (screen. width-parseInt (w)/2;
} Else {
L = parseInt (obj. left );
}
W = parseInt (w) + "px ";
H = parseInt (h) + "px ";
L = parseInt (l) + "px ";
T = parseInt (t) + "px ";
Var paramStr = "";
ParamStr + = ("dialogHeight =" + h + ";");
ParamStr + = ("dialogWidth =" + w + ";");
If (obj. center! = Undefined & obj. center! = Null ){
ParamStr + = "center =" + obj. center + ";"
} Else {
ParamStr + = ("dialogTop =" + t + ";");
ParamStr + = ("dialogLeft =" + l + ";");
}
ParamStr + = "resizable = yes; scroll = yes ";
// Alert (paramStr );
Var rv = window. showModalDialog (url, window, paramStr );
If (rv = undefined ){
Rv = window. returnValue;
}
If (obj. cb ){
Return obj. cb. call (rv, rv );
}
Return rv;
}
Function openWin (u, w, h ){
Var obj = {
Url: u,
Width: w,
Height: h
}
Return dialog (obj );
}
Function openWinWithCallBack (u, w, h, fun ){
Var obj = {
Url: u,
Width: w,
Height: h,
Cb: fun
}
Return dialog (obj );
}
Function openWindow (obj ){
If (obj. url = undefined | obj. url = null ){
Throw new Error ("please set obj. url ");
}
Var url = obj. url;
If (url. indexOf ("? ")! =-1 ){
Url = url + "& r _ =" + Math. random ();
} Else {
Url = url + "? R _ = "+ Math. random ();
}
// Alert (obj. width + "," + obj. height + "," + obj. top + "," + obj. left );
Var w;
If (! Obj. width ){
W = screen. width/2;
} Else {
W = parseInt (obj. width );
}
Var h;
If (! Obj. height ){
H = 500;
} Else {
H = parseInt (obj. height );
}
Var t;
If (! Obj. top ){
T = 50;
} Else {
T = parseInt (obj. top );
}
Var l;
If (! Obj. left ){
L = (screen. width-parseInt (w)/2;
} Else {
L = parseInt (obj. left );
}
W = parseInt (w );
H = parseInt (h );
L = parseInt (l );
T = parseInt (t );

// Window handle
Var name;
If (! Obj. name ){
Name = "win _" + new Date (). getTime ();
} Else {
Name = obj. name;
}
// Alert (name );
// Whether the window size can be changed
Var resizable = obj. resizable | "no ";
// Whether a scroll bar exists
Var scrollbars = obj. scrollbars | "yes ";
// Whether the status bar exists
Var status = obj. status | "no ";
// Whether the menu bar exists
Var menubar = obj. menubar | "no ";
// Whether a toolbar exists
Var toolbar = obj. toolbar | "no ";
// Whether the address bar exists
Var locations = obj. locations | "yes ";
Return window. open (url, name, "height =" + h + ", width =" + w + ", top =" + t + ", left =" + l + ", toolbar = "+ toolbar +", menubar = "+ menubar +", scrollbars = "+ scrollbars +", resizable = "+ resizable +", location = "+ locations + ", status = "+ status +", hotkeys = esc ");
}

// The Child page of mode window opening mode obtains the parent Page Object
Function getParent (){
Var p = "";
If (window. opener! = Undefined ){
P = window. opener;
}
Else {
P = window. dialogArguments;
};
Return p;
}

// Set the returnValue on the subpage of the mode window.
Function setReturnValue (v ){
If (window. opener! = Undefined ){
Window. opener. returnValue = v;
}
Else {
Window. returnValue = v;
};
}

// Sliding door
Function ScrollDoor (){
This. value = 0;
}
ScrollDoor. prototype = {
OnlyMenu: function (menus, openClass, closeClass) {// only menu no have content
Var _ this = this;
For (var I = 0; I <menus. length; I ++)
{
_ This. $ (menus [I]). flag = ++ this. value;
_ This. $ (menus [I]). value = I;
_ This. $ (menus [I]). onclick = function (){
For (var j = 0; j <menus. length; j ++)
{
_ This. $ (menus [j]). className = closeClass;
// _ This. $ (ps [j]). style. display = "none ";
}
_ This. $ (menus [this. value]). className = openClass;
// _ This. $ (ps [this. value]). style. display = "block ";
}
}
},
Sd: function (menus, ps, openClass, closeClass) {// two class
Var _ this = this;
If (menus. length! = Ps. length)
{
Alert ("the number of menu layers is different from the number of content layers! ");
Return false;
}
For (var I = 0; I <menus. length; I ++)
{
_ This. $ (menus [I]). flag = ++ this. value;
_ This. $ (menus [I]). value = I;
_ This. $ (menus [I]). onclick = function (){
For (var j = 0; j <menus. length; j ++)
{
_ This. $ (menus [j]). className = closeClass;
_ This. $ (ps [j]). style. display = "none ";
}
_ This. $ (menus [this. value]). className = openClass;
_ This. $ (ps [this. value]). style. display = "block ";
}
}
},
Sd3class: function (menus, ps, openClass, closeClass, middleClass) {// three class
Var _ this = this;
For (var x = 0; x <menus. length; x ++)
{
_ This. $ (menus [x]). state = _ this. $ (menus [x]). className = openClass? "Open": "close ";
}
If (menus. length! = Ps. length)
{
Alert ("the number of menu layers is different from the number of content layers! ");
Return false;
}
For (var I = 0; I <menus. length; I ++)
{
_ This. $ (menus [I]). flag = ++ this. value;
_ This. $ (menus [I]). value = I;
_ This. $ (menus [I]). onclick = function (){
For (var j = 0; j <menus. length; j ++)
{
_ This. $ (menus [j]). className = closeClass;
_ This. $ (ps [j]). style. display = "none ";
_ This. $ (menus [j]). state = "close ";
}
This. state = "open ";
_ This. $ (menus [this. value]). className = openClass;
_ This. $ (ps [this. value]). style. display = "block ";
}
_ This. $ (menus [I]). onmouseover = function (){
// Alert (this. state );
For (var j = 0; j <menus. length; j ++)
{
If (_ this. $ (menus [j]). state! = "Open ")
{
_ This. $ (menus [j]). className = closeClass;
_ This. $ (menus [j]). state = "close ";
}
}
If (this. state = "open ")
{
}
Else
{
This. className = middleClass;
}
}
_ This. $ (menus [I]). onmouseout = function (){
If (this. state! = "Open ")
{
This. className = closeClass;
}
}
}
},
$: Function (oid ){
If (typeof (oid) = "string ")
Return document. getElementById (oid );
Return oid;
}
}

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.