Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- <script src="jsscript.js"></script>
- </head>
- <body>
- <h1>Window Open and Close</h1>
- <form action="">
- <p>
- <input type="button" id="create-window" value="Create New Window">
- <input type="button" id="close-window" value="Close New Window">
- </p>
- </form>
- </body>
- </html>
- addEvent(window,'load',initialize);
- function initialize(){
- if(document.getElementById)
- {
- var oButtonCreate = document.getElementById("create-window");
- var oButtonClose = document.getElementById("close-window");
- if (oButtonCreate && oButtonClose)
- {
- oButtonCreate.onclick = makeNewWindow;
- obuttonClose.onclick =closeNewWindow;
- }
- }
- }
- var newWindow;
- function makeNewWindow()
- {
- newWindow = window.open("","","height=300, width=300")
- }
- function closeNewWindow()
- {
- if(newWindow)
- {
- newWindow.close();
- newWindow =null;
- }
- }
- function addEvent(to, type, fn){
- if(document.addEventListener){
- to.addEventListener(type, fn, false);
- } else if(document.attachEvent){
- to.attachEvent('on'+type, fn);
- } else {
- to['on'+type] = fn;
- }
- }
Add Comment
Please, Sign In to add comment