JSFiddle - React, Tailwind, and code Playground
HTML
<ul>
<li><a href="mypage.html?eventID=1" class="1">Event 1</a></li>
<li><a href="mypage.html?eventID=2" class="2">Event 2</a></li>
<li><a href="mypage.html?eventID=3" class="3">Event 3</a></li>
</ul>
<div id="modalMask">
<input type="button" onclick="closeModalPopupWindow()" id="closeModal" value="Close">
<div id="modalContent">
Loading...
</div>
</div>
<span id="output"></span>
CSS
#modalMask
{
display:none;
}
#modalContent /* This is for the content of the modal window: white bkgd, black border, centered, etc.*/
{
border:1px solid #000;
}
JavaScript
// Global variables
var ajax = getRequest(),
modalMask = document.getElementById('modalMask'),
modalContent = document.getElementById('modalContent'),
outPut = document.getElementById('output');
// Add event listeners for each link on the page:
for (var j = 0; j < document.links.length; ++j)
{
var link = document.links[j];
addEvent (link, 'mouseover',getOutput);
console.log(link.innerHTML);
}
// Function called to open the window:
function openModalPopupWindow()
{
modalMask.style.display = 'inline-block';
console.log('Modal shown');
}
// Function called to close the window:
function closeModalPopupWindow()
{
modalMask.style.display = 'none';
console.log('Modal hidden');
}
// Function to add event listeners:
function addEvent (obj, type, fn)
{
//Taken from p. 276, Ullman, Modern Javascript: Development and Design
if (obj && obj.addEventListener) obj.addEventListener (type, fn, false); //normal browsers
else if (obj && obj.attachEvent) obj.attachEvent ('on'+type, fn); //IE
}
//http://stackoverflow.com/questions/7165395/call-php-function-from-javascript
function getRequest()
{
var req = false;
try{
// most browsers
req = new XMLHttpRequest();
} catch (e){
// IE
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
// try an older version
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
return false;
}
}
}
return req;
}
function getOutput()
{
// 'this' refers to the element that called 'getOutput()' via its event handler:
var ID = this.className;
openModalPopupWindow();
if ( ajax && ajax.readyState > 0 && ajax.readyState < 4 )
{
// Abort previous unfinished requests:
ajax.abort();
console.log('Aborted previous request.');
}
ajax.onreadystatechange = function()
{
console.log('Readystate: ' + ajax.readyState);
...