First, you do not need # in the link. Just call e.preventDefault(); to stop the execution of the link.
For security reasons, you cannot open every link, for example. Google
Also, you can not use the switch, because you always need to double-click it if the frame is already open.
here is a working violin
HTML
<div class="links"> <a class="openpop" href="http://getbootstrap.com/">Link 1</a> <a class="openpop" href="http://www.jsfiddle.net">Link 2</a> <a class="openpop" href="http://www.w3schools.com">Link 3</a> </div> <div class="wrapper"> <div class="popup"> <iframe src=""> <p>Your browser does not support iframes.</p> </iframe> <a href="#" class="close">X</a> </div> </div>
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 need to make some styling changes for a better look :)
source share