how to make a pop up that opens in the same window

2

I would like to know how to make a pop up that opens in the same window after the user clicks a button on the page. The content of the pop up would be on a separate page.

    
asked by anonymous 02.02.2018 / 22:52

1 answer

3

Use window.open :

<button onclick="window.open('pagina.html','_blank','width=400, height=300')">Abrir popup</button>
  

It's important to know that the popup will only work by event    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 out at MDN .

Edit

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>
    
02.02.2018 / 23:08