Last active
December 20, 2021 11:45
-
-
Save krabs-github/0b6d3fbde66135de664a0b61847240ae to your computer and use it in GitHub Desktop.
[JavaScript - Open, Close, and Move Windows] JavaScript - Open, Close, and Move Windows #JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myWindow = window.open("http://google.com","myWindow"); | |
// opens SO in the same window | |
window.open("http://stackoverflow.com","myWindow"); | |
// the following will only work if it's the same domain, else subject to SOP - | |
// so in the case of initially opening it with google, this won't work! | |
myWindow.document.location.href = "/example/test.html"; | |
// closes your window | |
myWindow.close(); | |
----------- | |
MOVE WINDOW | |
function openWin() { | |
myWindow = window.open('', '', 'width=200, height=100'); // Opens a new window | |
myWindow.document.write("<p>This is 'myWindow'</p>"); // Some text in the new window | |
} | |
function moveWin() { | |
myWindow.moveTo(500, 100); // Moves the new window | |
myWindow.focus(); // Sets focus to the new window | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment