I know that <a href=http://www.example.com target=_blank>Click here</a>
opens the link in a new tab (default behaviour in Chrome and Firefox) and that
<a href=http://www.example.com onclick=window.open('http://www.example.com',
'newwindow', 'width=700,height=500'); return false;>Click here</a>
opens it in a new window.
But how to open an external page in a modal popup (centered on screen, rest of the original page darkened)?
Is there a nice way to do it?
I tried the following code, but it doesn't seem to be working (click: popup opens, reclick, it closes, reclick on link: it doesn't open anymore. Also the iframe doesn't load).
document.getElementById(a).onclick = function(e) {
e.preventDefault();
document.getElementById(popup).style.display = block;
document.getElementById('iframe').src = http://example.com;
document.getElementById('page').className = darken;
setTimeout(function() {
document.getElementById('page').onclick = function() {
document.getElementById(popup).style.display = none;
document.getElementById('page').className = ;
}
}, 100);
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%; }
<div id=page>
<a href= id=a>Click me</a><br>
Hello<br>
Hello<br>
<div id=popup>
External website:
<iframe id=iframe></iframe>
</div>
</div>