Videos
4 Ways to Create a Modal Popup Box with Html, CSS and Vanilla JavaScript - The Code Angle
Here is a simple solution that will allow you to fetch value from opened window. All you need is to inject JavaScript code into opened window that will interact with the parent window using window.opener:
HTML
<input id="value" />
<button onclick="openWindow();">Open</button>
JavaScript
function openWindow() {
var i, l, options = [{
value: 'first',
text: 'First'
}, {
value: 'second',
text: 'Second'
}],
newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
newWindow.document.write("<select onchange='window.opener.setValue(this.value);'>");
for(i=0,l=options.length; i<l; i++) {
newWindow.document.write("<option value='"+options[i].value+"'>");
newWindow.document.write(options[i].text);
newWindow.document.write("</option>");
}
newWindow.document.write("</select>");
}
function setValue(value) {
document.getElementById('value').value = value;
}
Working example here: http://jsbin.com/uqamiz/1/edit
The easiest way is to have a superimposed div with a a high z-index, with transparent background acting as an overlay. You could then have another div which is centered above the overlay(with higher z-index) and containing the list markup
CSS
#shim {
opacity: .75;
filter: alpha(opacity=75);
-ms-filter: "alpha(opacity=75)";
-khtml-opacity: .75;
-moz-opacity: .75;
background: #B8B8B8;
position: absolute;
left: 0px;
top: 0px;
height: 100%;
width: 100%;
z-index:990
}
#msgbx {
position: absolute;
left: 50%;
top: 50%;
height: 150px;
width: 350px;
margin-top: -75px;
margin-left: -175px;
background: #fff;
border: 1px solid #ccc;
box-shadow: 3px 3px 7px #777;
-webkit-box-shadow: 3px 3px 7px #777;
-moz-border-radius: 22px;
-webkit-border-radius: 22px;
z-index:999
}
HTML
<div id="shim"></div>
<div id="msgbx">inject list markup here</div>
To show popup
document.getElementById('shim').style.display=document.getElementById('msgbx').style.display ="block";
To Hide
document.getElementById('shim').style.display=document.getElementById('msgbx').style.display ="none";
It can be very easily done using pure CSS and JS...
Please find here the fiddle - Please let me know if this helps.
Your popup html code can be like-
<div id="click" onClick="showPopUp()">Click here to see the pop up</div>
<div id="popup">
<div id="header">Welcome to Pop-Up
<img src="http://icongal.com/gallery/image/158734/actions_window_close.png" width="20px" onclick="closeThis()" />
</div>
<div>THIS IS THE TEXT OF POP-UP</div>
</div>
Basic CSS -
#popup {
position:absolute;
display: none;
left:50%;
top:10px;
}
JS Code -
1) To Show the popup on click of the text
function showPopUp() {
document.getElementById("popup").style.display = "block";
}
2) To check/hide a pop up when clicked anywhere else on the page -
document.onclick=check;
function check(e) {
var target = (e && e.target) || (event && event.srcElement);
var obj = document.getElementById('click');
if(target!=obj){document.getElementById('popup').style.display='none'}
}
I put together an overly simplistic jsFiddle demo of how a popup is made. Here is the magic:
//Display Popup method - you can modify this to add parameters
function displayPopup(event) {
//dynamically create a div, button, and inner text
var p = document.createElement('div'),
b = document.createElement('button'),
t = document.createTextNode("Text and stuff");
//add popup class to newly created div
p.className += 'popup';
//Add text to close button element
b.innerHTML = "close";
//Append text to popup div
p.appendChild(t);
//Bind click event to button element
b.onclick = closePopup;
//Append button to popup div, and append popup to document body
p.appendChild(b);
document.body.appendChild(p);
p.style.display="block";
//This function hides the popup
function closePopup(event){
p.style.display="none";
}
}
It should by no means be considered complete or production material, but I hope it helps you get started on the right path to extending it to achieve the functionality you're looking for.