【问题标题】:add external link in my popup lightbox在我的弹出式灯箱中添加外部链接
【发布时间】:2017-12-23 21:47:29
【问题描述】:

在我的网站中,我想在框架中显示谷歌网站,但这是我的错误:拒绝在框架中显示,因为它将“X-Frame-Options”设置为“SAMEORIGIN”

所以我想在弹出式灯箱中显示链接,但我真的不知道我该怎么做!这是我的弹出灯箱代码:

$(document).ready(function() {

  var id = '#dialog';

  //Get the screen height and width
  var maskHeight = $(document).height();
  var maskWidth = $(window).width();

  //Set heigth and width to mask to fill up the whole screen
  $('#mask').css({
    'width': maskWidth,
    'height': maskHeight
  });

  //transition effect
  $('#mask').fadeIn(500);
  $('#mask').fadeTo("slow", 0.9);

  //Get the window height and width
  var winH = $(window).height();
  var winW = $(window).width();

  //Set the popup window to center
  $(id).css('top', winH / 2 - $(id).height() / 2);
  $(id).css('left', winW / 2 - $(id).width() / 2);

  //transition effect
  $(id).fadeIn(2000);

  //if close button is clicked
  $('.window .close').click(function(e) {
    //Cancel the link behavior
    e.preventDefault();

    $('#mask').hide();
    $('.window').hide();
  });

  //if mask is clicked
  $('#mask').click(function() {
    $(this).hide();
    $('.window').hide();
  });

});
#mask {
  position: absolute;
  left: 0;
  top: 0px;
  width: 100% !important;
  height: 750px !important;
  z-index: 9000;
  background-color: #fff;
  display: none;
}

#boxes .window {
  position: absolute;
  left: 0!important;
  top: 0px!important;
  width: 100%;
  height: 750px;
  display: none;
  z-index: 9999;
  padding: 20px;
  text-align: center;
}

#boxes #dialog {
  left: 0!important;
  top: 0px!important;
  width: 100%;
  height: 750px;
  padding: 10px;
  background-color: #ccc;
  font-family: 'Segoe UI Light', sans-serif;
  font-size: 15pt;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="boxes">
  <div id="dialog" class="window">
    Your Content Goes Here
  </div>
  <div id="mask"></div>
</div>

需要添加更多文字来验证我的帖子,但都说了!!

【问题讨论】:

    标签: javascript html modal-dialog popup lightbox


    【解决方案1】:

    您可以使用&lt;iframe&gt; 来显示来自外部 URL 的内容。这不适用于每个 URL,因为有些 URL 会设置 X-Frame-Options 以禁止将页面嵌入到 &lt;iframe&gt; 中。基本上,您会将#dialog 的 HTML 设置为 &lt;iframe&gt;,并将 src 设置为您要显示的 URL,例如:

    $(id).html(`<iframe src="https://www.theonion.com/" frameborder="0" width="100%" height="100%" ></iframe>`);
    

    这是一个例子:

    $(document).ready(function() {
    
      var id = '#dialog';
      
      $(id).html(`<iframe src="https://www.theonion.com/" frameborder="0" width="100%" height="100%" ></iframe>`);
    
      //Get the screen height and width
      var maskHeight = $(document).height();
      var maskWidth = $(window).width();
    
      //Set heigth and width to mask to fill up the whole screen
      $('#mask').css({
        'width': maskWidth,
        'height': maskHeight
      });
    
      //transition effect
      $('#mask').fadeIn(500);
      $('#mask').fadeTo("slow", 0.9);
    
      //Get the window height and width
      var winH = $(window).height();
      var winW = $(window).width();
    
      //Set the popup window to center
      $(id).css('top', winH / 2 - $(id).height() / 2);
      $(id).css('left', winW / 2 - $(id).width() / 2);
    
      //transition effect
      $(id).fadeIn(2000);
    
      //if close button is clicked
      $('.window .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
    
        $('#mask').hide();
        $('.window').hide();
      });
    
      //if mask is clicked
      $('#mask').click(function() {
        $(this).hide();
        $('.window').hide();
      });
    
    });
    #mask {
      position: absolute;
      left: 0;
      top: 0px;
      width: 100% !important;
      height: 750px !important;
      z-index: 9000;
      background-color: #fff;
      display: none;
    }
    
    #boxes .window {
      position: absolute;
      left: 0!important;
      top: 0px!important;
      width: 100%;
      height: 750px;
      display: none;
      z-index: 9999;
      padding: 20px;
      text-align: center;
    }
    
    #boxes #dialog {
      left: 0!important;
      top: 0px!important;
      width: 100%;
      height: 750px;
      padding: 10px;
      background-color: #ccc;
      font-family: 'Segoe UI Light', sans-serif;
      font-size: 15pt;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="boxes">
      <div id="dialog" class="window">
        
      </div>
      <div id="mask"></div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多