$(document).ready(function(){
$('a').bind('click', function(e){
$('<iframe/>', {
src: $(this).attr('href'),
class: 'myiframe',
css: {
position: 'absolute',
width: '200px',
height: '200px',
top: window.innerHeight / 2 + 300,
left: window.innerWidth / 2 + 300
}
}).appendTo(document.body);
return(false);
});
$(document.body).bind('keydown', function(e){
if(e.which === 27)
$('.myiframe').remove();
});
});
I have poorly calculated the top / left coordinates there, you might want to replace this with the css class. Use class: "classname"for this in creation.
Links: . bind () , attr () , . appendTo () , jQuery Core
jAndy source
share