让新窗口失去并获得焦点

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. var myWindow;
  6. function openWin() {
  7. myWindow = window.open("", "", "width=400, height=200");
  8. myWindow.blur();
  9. }
  10. function blurWin() {
  11. myWindow.blur();
  12. }
  13. function focusWin() {
  14. myWindow.focus();
  15. }
  16. </script>
  17. </head>
  18. <body>
  19.  
  20. <input type="button" value="打开新窗口" onclick="openWin()">
  21. <input type="button" value="失焦新窗口" onclick="blurWin()">
  22. <input type="button" value="聚焦新窗口" onclick="focusWin()">
  23.  
  24. </body>
  25. </html>