Guest User

Untitled

a guest
Feb 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>Document</title>
  5. <script src="jsscript.js"></script>
  6. </head>
  7. <body>
  8. <h1>Window Open and Close</h1>
  9. <form action="">
  10. <p>
  11. <input type="button" id="create-window" value="Create New Window">
  12. <input type="button" id="close-window" value="Close New Window">
  13. </p>
  14. </form>
  15. </body>
  16. </html>
  17.  
  18.  
  19.  
  20. addEvent(window,'load',initialize);
  21.  
  22. function initialize(){
  23. if(document.getElementById)
  24. {
  25. var oButtonCreate = document.getElementById("create-window");
  26. var oButtonClose = document.getElementById("close-window");
  27. if (oButtonCreate && oButtonClose)
  28. {
  29. oButtonCreate.onclick = makeNewWindow;
  30. obuttonClose.onclick =closeNewWindow;
  31. }
  32. }
  33. }
  34.  
  35. var newWindow;
  36.  
  37. function makeNewWindow()
  38. {
  39. newWindow = window.open("","","height=300, width=300")
  40. }
  41. function closeNewWindow()
  42. {
  43. if(newWindow)
  44. {
  45. newWindow.close();
  46. newWindow =null;
  47. }
  48. }
  49.  
  50. function addEvent(to, type, fn){
  51. if(document.addEventListener){
  52. to.addEventListener(type, fn, false);
  53. } else if(document.attachEvent){
  54. to.attachEvent('on'+type, fn);
  55. } else {
  56. to['on'+type] = fn;
  57. }
  58. }
Add Comment
Please, Sign In to add comment