How to open a pop-up without using Javascript?

Asked

Viewed 20,055 times

12

How to open a pop-up without using onclick or any other Javascript function?

  • Just one question, why not use Javascript? I think what @bfavaretto said, you might want a "modal" (actually a div overlaid the other elements), but even so this "modal" can use Javascript (or the pseudo :target as in @Zuul’s reply)

  • Have you found a solution to this answer? Did any of the answers help?

4 answers

26

You can use CSS3 to create a popup, open and close it without using Javascript.

The trick is in using pseudo class target which allows us to change declarations to the element .modalDialog and thus present the same.

Example

.modalDialog {
  position: fixed;
  font-family: Arial, Helvetica, sans-serif;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 99999;
  opacity: 0;
  -webkit-transition: opacity 400ms ease-in;
  -moz-transition: opacity 400ms ease-in;
  transition: opacity 400ms ease-in;
  pointer-events: none;
}
.modalDialog:target {
  opacity: 1;
  pointer-events: auto;
}
.modalDialog > div {
  width: 400px;
  position: relative;
  margin: 10% auto;
  padding: 5px 20px 13px 20px;
  border-radius: 10px;
  background: #fff;
  background: -moz-linear-gradient(#fff, #999);
  background: -webkit-linear-gradient(#fff, #999);
  background: -o-linear-gradient(#fff, #999);
}
.close {
  background: #606061;
  color: #FFFFFF;
  line-height: 25px;
  position: absolute;
  right: -12px;
  text-align: center;
  top: -10px;
  width: 24px;
  text-decoration: none;
  font-weight: bold;
  -webkit-border-radius: 12px;
  -moz-border-radius: 12px;
  border-radius: 12px;
  -moz-box-shadow: 1px 1px 3px #000;
  -webkit-box-shadow: 1px 1px 3px #000;
  box-shadow: 1px 1px 3px #000;
}
.close:hover {
  background: #00d9ff;
}
<a href="#openModal">Open Modal</a>

<div id="openModal" class="modalDialog">
  <div>
    <a href="#close" title="Close" class="close">X</a>
    <h2>Popup</h2>
    <p>Isto é uma popup toda bonitinha a funcionar apenas com CSS3.</p>
  </div>
</div>

Example in detail in (c) Webdesigner Depot.

  • Very good, really the :target was very well employed in the example, thanks for the contribution. The +1 was already guaranteed :)

  • I was late, but sensational!

8

This method does not use Javascript or CSS3. It basically works like this: The page is inside a container and the popup is hidden in an overflow part of the container. When you click the anchor, the user is taken to that part of the container.

#container, #popup{
    width: 600px;
    height: 600px;
    overflow: hidden;
}
#pag{
    width: 600px;
    height: 1200px;
}
#popup{
    margin-top: 600px;
    background-color: grey
}
<div id="container">
    <div id="pag">
        <a href="#popup">Abrir popup</a><p>
        Conteúdo da pagina
        <div id="popup">
            <a href="#pag">fechar popup</a><p>
            Conteúdo da POPUP
        </div>
    </div>  
</div>

  • Very creative, I added Stacksnippet for others to test your example

5

The best thing to do is to force the opening in another tab (or window, who decides is the browser):

<a href="http://google.com" target="_blank">Google</a>
  • hi friend, I would like to do like Facebook, Twitter etc.

  • 3

    @Xironakamura Facebook, Twitter etc use Javascript! And a lot of it...

  • 1

    @Xironakamura Maybe it’s a modal dialogue, not a pop-up you’re looking for. Like this: http://answall.com/questions/51718/caixa-de-aviso-ap%C3%B3s-clique-em-div

  • As the question describes, it really is the correct answer rs +1

  • 1

    Friends I think is a same pop up. I want to click on the button and open a window with a page of the site. type o Twitter (https://about.twitter.com/resources/buttons) can be in Javascript but as long as the link can be the same as on Twitter.

  • So @Xironakamura, like the one on Twitter, is what they explain in that other question that I pointed out as a duplicate of their previous question: http://answall.com/questions/21240/howto open up

  • opa amigo, mas eu queria sem o window.open. lá no Twitter ele(link) esta totalmente "limpo" sem esses funções. <a href="https://twitter.com/share" class="twitter-share-button" data-via=""">Tweet</a>

  • @Xironakamura The twitter button certainly includes some JS to do this, you can not open this type of window without window.open. Only that the window.open does not need to be inside the tag <a>, the JS must be separate.

  • @Xironakamura <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>&#xA;<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> The code with window.open should be in this //platform.twitter.com/widgets.js

  • It’s A LOT kkkkkk code... but I couldn’t find the window.open.

  • @Xironakamura if you look closer will notice a d.createElement and the url ://platform.twi‌​tter.com/widgets.js ie, this url contains the rest of javascript and if you open in the browser and use Ctrl+F and search the word window.open you will probably find it there.

Show 6 more comments

-2

I was able to do/... what do you think of the code? Can you improve? And if js is disabled in the client browser, would it have some way to execute the code?

<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>  

<script language="JavaScript">
$(document).ready(function() {
$("#enviar").click(function( e ){
e.preventDefault();

var width = 550;
var height = 550;

var left = 99;
var top = 99;

window.open(enviar,'janela', 'width='+width+', height='+height+',top='+top+'left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

 });
 });
</script>

<a href="https://twitter.com/share" id="enviar" data-text="https://www.google.com/?gws_rd=ssl">Tweet</a>
  • The title says no Javascript, so the answer to me is kind of illogical, not to be boring, but in my view the other answers are correct and your only wrong. I hope you don’t mind, we are a community of questions and answers and not a community of support and discussions, welcome :)

  • Hi William, the problem is that I was not very clear in the question. And when Adm made the issue the same did not match my reality. But I was able to solve the problem and I just want answers to the technical questions I mentioned above.

  • Good afternoon, it was not an Adm who edited, we are a community anyone can edit, as long as it is approved by user with more experience, here we are not a forum for debates, but rather a Q&A, to be more objective, we are a community of questions and answers, if the answer does not match the question, technically it is not an answer. If the question was something like this: How does Tweeter use javascript-free pop-ups? perhaps the answer was valid (although it would be a very bad question, so the question speaks:...

  • ...How to open a pop-up without using onclick or any other Javascript function? and the answer has to be according to the question, of course it may contain more details. In other words, your question is not just for you, but for the whole community, try to make it useful to others, because if it’s not a question more asking for support than a question within the scope of the community... that’s just my opinion and if anyone disagrees, please can criticize me I will not take it badly, I’m just trying to steer.

Browser other questions tagged

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