Opening an external website in a modal popup

前端 未结 3 1137
小鲜肉
小鲜肉 2021-01-07 06:33

I know that Click here opens the link in a new tab (default behaviour in Chrome an

3条回答
  •  时光取名叫无心
    2021-01-07 07:20

    document.getElementById("a").onclick = function(e) {
      e.preventDefault();
      var isInit = true; // indicates if the popup already been initialized.
      var isClosed = false; // indicates the state of the popup
      document.getElementById("popup").style.display = "block";
      document.getElementById('iframe').src = "http://example.com";
      document.getElementById('page').className = "darken";
      document.getElementById('page').onclick = function() {
        if(isInit){isInit=false;return;}
        if(isClosed){return;} //if the popup is closed, do nothing.
        document.getElementById("popup").style.display = "none";
        document.getElementById('page').className = "";
        isClosed=true;
      }
      return false;
    }
    #popup { 
      display: none; 
      border: 1px black solid;
      width: 400px; height: 200px; 
      top:20px; left:20px;
      background-color: white;
      z-index: 10;
      padding: 2em;
      position: fixed;
    }
    
    .darken { background: rgba(0, 0, 0, 0.7); }
    
    #iframe { border: 0; }
    
    html, body, #page { height: 100%; }
    Click me
    Hello
    Hello

提交回复
热议问题