Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Test Page</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  body {
    font-family: sans-serif;
  }
  p {
    margin: 0px;
  }
  iframe.shim {
    width:            100%;
    height:           100%;
    position:         absolute;
    left:             0px;
    top:              0px;
    z-index:          100;
    background-color: #fff;
    opacity:          0.5;                 /* Standard */
    filter:           alpha(opacity = 50); /* For IE */
  }
  div.overlay {
    z-index:          101;
    border:           1px solid black;
    background-color: #ecc;
    position:         absolute;
    left:             100px;
    top:              100px;
  }
</style>
</head>
<body>
  <input type='button' id='btnPopup' value='Click for Pop-Up'>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
  <p>This is text on the page</p>
</body>
</html>
 
window.onload = function() {
  
  document.getElementById('btnPopup').onclick = function() {
    doVerySimplePopup("Hi there, click me to dismiss", function() {
      display("Popup closed");
    });
  };
  
  function doVerySimplePopup(text, callback) {
    var shim, div, parent = document.body;
    
    shim = document.createElement('iframe');
    shim.className = 'shim';
    parent.appendChild(shim);
    
    div = document.createElement('div');
    div.className = 'overlay';
    div.innerHTML = text;
    parent.appendChild(div);
    div.onclick = function() {
      parent.removeChild(div);
      parent.removeChild(shim);
      if (typeof callback === "function") {
        try { callback(); } catch (e) { }
      }
    };
  }
  
  function display(msg) {
    var p = document.createElement('p');
    p.innerHTML = msg;
    document.body.appendChild(p);
  }
};
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers