2
I would like to know how to do a pop up that opens in the same window after the user clicks a button on the page. The contents of the pop up would be on a separate page.
2
I would like to know how to do a pop up that opens in the same window after the user clicks a button on the page. The contents of the pop up would be on a separate page.
2
Use the window.open
:
<button onclick="window.open('pagina.html','_blank','width=400, height=300')">Abrir popup</button>
It is important to know that the popup will only work through the event of click by the user, otherwise the browser will block by default.
Syntax of window.open
:
window.open(URL, nome, propriedades, replace)
Detailed information you can check on MDN.
Open a popup via iframe
:
function abrirPopUp(){
var pagina = "pagina.html";
var popup = document.querySelector("iframe");
popup.src = pagina;
popup.style.display = "block";
}
iframe{
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
position: fixed;
display: none;
position: fixed;
z-index: 99;
width: 500px;
height: 300px;
}
<button onclick="abrirPopUp()">Abrir popup</button>
<iframe scrolling="no" frameborder="0"></iframe>
Browser other questions tagged php html popup
You are not signed in. Login or sign up in order to post.
window.open opens a new window, wanted the popup to be in the same window where the click was given.
– user90441
@Ehren999 Good evening!! I understood now what you wanted. You want to open as if it were a modal. I will reformulate the answer, you wait a few minutes?
– Sam
sure, thank you!
– user90441
@Ehren999 I added an option via iframe in the reply.
– Sam
thank you very much!
– user90441