Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

javascript - How to open link in popup box?

I'd like to open this link as a popup box:

  <a href="/upload/" onclick="window.open(this.href, 'windowName', 'width=500, height=350, left=24, top=24, scrollbars, resizable'); return false;">Upload pic</a>

Currently, it opens in a window, but what I want is a bare popub box instead. How to do so using js or jQuery?

Update: The link is inside a form group and using iframe, as suggested by many here, causes the form to submit (not sure why though). So I look for a non-iframe solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Build your own popup box with an iframe element;

onclick you can change the src of the iframe to the one you want


document.getElementById('modalBtn').onclick = displayPopup;

function displayPopup() {
  var popup = document.getElementById("popup");
  var frame = document.getElementById('popupFrame');
  frame.src = "https://www.bing.com";
  popup.style.display = "block";
}
#popup {
  width: 320px;
  height: 300px;
  margin: 0 auto;
  box-shadow: 1px 1px 1px 1px black;
  display: none;
}
#popup iframe {
  width: 100%;
  height: 100%
}
<div id="popup">
  <iframe id="popupFrame" src=""></iframe>
</div>

<button id="modalBtn">Display Popup</button>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...