2017-12-04 7 views
0

ポップアップウィンドウをメインウィンドウの背後に表示します。 ウィンドウ1はメインウィンドウで、ウィンドウ2はポップアップウィンドウです。 誰かがウィンドウ1をクリックすると、ウィンドウ1の後ろにウィンドウ2が表示されます。 imはすでにwindow.focuswindow.blurを試していますが、誰も動作しません。これを覚えている、私はちょうどこれを学習のために作っている。メインウィンドウの背後にポップアップウィンドウが表示されます。JavaScriptを使用しています

<script type="text/javascript"> 
     var popup = function() { 
     var lastShownTs = +localStorage.getItem("lastShown"); 
     var currentDate = new Date(); 
     currentDate.setHours(0, 0, 0, 0); 
     var lastShown = null; 
     if (!isNaN(lastShownTs)) { 
      lastShown = new Date(lastShownTs); 
      lastShown.setHours(0, 0, 0, 0); 
     } 
     if (lastShown == null || lastShown.getTime() != currentDate.getTime()) { 
      window.open("example.com", "Window", "status=1,toolbar=1,width=1,height=1,left=5000,top=5000,scrollbars=1,resizable=1"); 
      localStorage.setItem("lastShown", currentDate.getTime()); 
     } 
window.focus(); 
popup.blur(); 
     } 
    </script> 

    <body onclick="popup()"></body> 

答えて

0

あなたが探しているものは「ポップアンダー」と呼ばれています。 https://developer.mozilla.org/en-US/docs/Web/API/Window/openを参照してください。

代わりには、ここに...タブを使用してチートであるクロム62.0.3202.62テスト済み

<script> 
    function popunder() { 
     var currentURL = document.URL; 
     window.open(currentURL, '_blank', 'toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes'); 
     window.location = 'http://www.stackoverflow.com'; 
    } 

</script> 
<a href="#" onclick="popunder()">Click here!</a> 

+0

それは何を探していない –

関連する問題