9

I need to replace our Ajax Modal Popup controls with a JavaScript equivalent. We use this as a simple context sensitive help type popup. I did a quick browse but didn't see quite what I was looking for. I just need some text and a simple Close button/link, but I would like the page darkened below the popup, as it does with the Ajax modal control.

Can anyone suggest a nice JavaScript popup/help type solution that you've used?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SunfiShie
  • 396
  • 1
  • 3
  • 11

4 Answers4

25

I can provide you the code. Do your modifications as necessary, OK?

Page JavaScript:

function myPop() { 
    this.square = null;
    this.overdiv = null;

    this.popOut = function(msgtxt) {
        //filter:alpha(opacity=25);-moz-opacity:.25;opacity:.25;
        this.overdiv = document.createElement("div");
        this.overdiv.className = "overdiv";

        this.square = document.createElement("div");
        this.square.className = "square";
        this.square.Code = this;
        var msg = document.createElement("div");
        msg.className = "msg";
        msg.innerHTML = msgtxt;
        this.square.appendChild(msg);
        var closebtn = document.createElement("button");
        closebtn.onclick = function() {
            this.parentNode.Code.popIn();
        }
        closebtn.innerHTML = "Close";
        this.square.appendChild(closebtn);

        document.body.appendChild(this.overdiv);
        document.body.appendChild(this.square);
    }
    this.popIn = function() {
        if (this.square != null) {
            document.body.removeChild(this.square);
            this.square = null;
        }
        if (this.overdiv != null) {
        document.body.removeChild(this.overdiv);
        this.overdiv = null;
        }

    }
}

Now the HTML page, using the JavaScript file:

<html> 
  <head>
    <script type="text/javascript" src="NAME OF THE PAGE!.js"></script>
    <style>
        div.overdiv { filter: alpha(opacity=75);
                      -moz-opacity: .75;
                      opacity: .75;
                      background-color: #c0c0c0;
                      position: absolute;
                      top: 0px;
                      left: 0px;
                      width: 100%; height: 100%; }

        div.square { position: absolute;
                     top: 200px;
                     left: 200px;
                     background-color: Menu;
                     border: #f9f9f9;
                     height: 200px;
                     width: 300px; }
        div.square div.msg { color: #3e6bc2;
                             font-size: 15px;
                             padding: 15px; }
    </style>
  </head>
  <body>
    <div style="background-color: red; width: 200px; height: 300px;
                padding: 20px; margin: 20px;"></div>

    <script type="text/javascript">
        var pop = new myPop();
        pop.popOut("Jose leal");
    </script>
  </body>
</html>

Hope that this can help.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
José Leal
  • 7,989
  • 9
  • 35
  • 54
7

I've used the simplemodal jQuery plugin and I've been quite happy with it. You can check it out here.

Andrew Van Slaars
  • 1,816
  • 1
  • 14
  • 20
0

Maybe you are looking for something like this? [ui.jquery.com]

It's the simplest one, and can come bundled with a lot of other eye candy. Of course you could also look around the rest of the jQuery plug-ins page, specially the Windows and Overlays section.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Esteban Küber
  • 36,388
  • 15
  • 79
  • 97
0

I developed a javascript library called Msg. It allows to easily create a modal window / popup. It creates an overlay behind it that darkens the background. It has no close button but it can be closed by clicking the background overlay.

madprops
  • 3,909
  • 5
  • 34
  • 42