JavaScript pops up a new window and controls how the window moves to the specified location
- 2020-05-26 07:50:14
- OfStack
This example shows how JavaScript can pop up a new window and control its movement to a specified location. Share with you for your reference. The details are as follows:
The JS code below pops up a new window through window.open, and then controls the window to move to the specified location through the JS code
<!DOCTYPE html>
<html>
<head>
<script>
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function moveWin()
{
myWindow.moveTo(0,0);
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="Open 'myWindow'"
onclick="openWin()" />
<br><br>
<input type="button" value="Move 'myWindow'"
onclick="moveWin()" />
</body>
</html>
I hope this article has helped you with your javascript programming.