How to Load iframe content in Popup div?

前端 未结 3 548
情歌与酒
情歌与酒 2021-02-08 19:57

How to Load iframe content in Popup div. popup div will be open on click of each link from each link, page url will load to iframe href inside popup div.

$(docu         


        
3条回答
  •  遥遥无期
    2021-02-08 20:19

    First, you don't need # in the link. Just call e.preventDefault(); to stop the link from executing.

    For security reasons you can't open every link eg. google.

    Also you might not use toggle because you allways have to click it twice if a frame is opend already.

    here is a working fiddle

    html

    
    

    jquery

    $(document).ready(function () {
        $(".popup").hide();
        $(".openpop").click(function (e) {
            e.preventDefault();
            $("iframe").attr("src", $(this).attr('href'));
            $(".links").fadeOut('slow');
            $(".popup").fadeIn('slow');
        });
    
        $(".close").click(function () {
            $(this).parent().fadeOut("slow");
            $(".links").fadeIn("slow");
        });
    });
    

    of course you have to do some changes in styling for better view experience :)

提交回复
热议问题