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

Asked

Viewed 1,571 times

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.

1 answer

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.

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>

  • window.open opens a new window, wanted the popup to be in the same window where the click was given.

  • @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?

  • sure, thank you!

  • @Ehren999 I added an option via iframe in the reply.

  • thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.