Javascript window.open a solution to a problem where a new window cannot be opened again
- 2020-03-30 02:39:31
- OfStack
Javascript open window is used in some places on the system. For example, open a window in fixed mode to prevent the user from doing anything else.
Parameters:
parameter | Value range | instructions
alwaysLowered | yes/no | Specifies that the window is hidden behind all Windows
alwaysRaised | yes/no | Specifies that the window is suspended over all Windows
depended | yes/no | Whether to close at the same time as the parent window
directories | yes/no | Nav2 and 3 Is the directory bar visible
height | pixel value | Window height
hotkeys | yes/no | Set a safe exit hotkey in a window without a menu bar
innerHeight | pixel value | The pixel height of the document in the window
innerWidth | pixel value | The pixel width of the document in the window
location | yes/no | Whether the position bar is visible
menubar | yes/no | Is the menu bar visible
outerHeight | pixel value | Set the window ( Including decorative border ) Pixel height of
outerWidth | pixel value | Set the window ( Including decorative border ) Pixel width of
resizable | yes/no | Is the window size adjustable
screenX | pixel value | The pixel length of the window from the left edge of the screen
screenY | pixel value | The pixel length of the window from the edge of the screen
scrollbars | yes/no | Does the window have a scroll bar
titlebar | yes/no | Is the window title bar visible
toolbar | yes/no | Is the window toolbar visible
Width | pixel value | The pixel width of the window
z-look | yes/no | Whether the window floats above other Windows after being activated
Example:
window.open("page.html", "newwindow", "height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no,resizable=no, location=no, status=no")
After calculating the height and width according to the resolution, open:
var ht = screen.height-98;
var widhh = screen.width - 20;
window.opener = null;
window.open("", "_self");
window.open("Main.aspx", "newwindow" + JsGuid(),
"height=" + ht + ", width=" + widhh + ",
depended=yes,top=0,left=0,toolbar=no, menubar=no,
scrollbars=yes, resizable=no, location=no, status=yes");
window.close();
And close the original window.
Question:
If the system exits after window.open, an error occurs when you open a new page using window.open again.
Google for a long time also did not find. One thing that should not happen very often is definitely a configuration problem.
Where we can see that the second argument to window.open is the name of the new window. The name cannot be repeated.
If it repeats, it will always refresh in this window.
So I added a random GUID function of js.
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
};
function JsGuid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
Window.open (" main.aspx ", "newwindow" + JsGuid());
OK, problem solved.