Search code examples
popupinfobox

Creating unblockable Pop Up on click


how can i create a popup which isn't blocked when a user clicks on a specific text? So if someone want more to know about something the person can just click the text an get a pop up like on following website.

http://www.berater-mainz.de/cms/struktur.html

Is there a simple way? Does anyone has an idea?


Solution

  • Do not use the JavaScript alert function as this can be blocked by browsers. Instead use a hidden div that you can show when a button is clicked.

    First you will have to include the JQuery library in your HTML File by including a link to it in the head. A library is basically a lot of code written for you so that you can invoke complicated functions with less code.

    <head>
        <script type="text/javascript"> 
        document.write([ "\<script src='", ("https:" == document.location.protocol) ? "https://" : "http://", "ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js' type='text/javascript'>\<\/script>" ].join('')); 
       </script> <!-- This script tag includes JQuery's functions in you page. -->
    </head>
    
    <div style='display:none;'><!--This is the popup box!--></div> 
    <script>
    $(function(){ 
        $('button').on('click', function(){ //When the button is clicked...
            $('div').css('display', 'block'); //Show the previously hidden div
        });
    });
    </script>
    

    ... as far as I know, there is no way to do it without JavaScript.