Reputation: 168
I wrote a sample html page to show a popup div, it's working in firefox, but not in IE. it said the function is undefined.
Here is my page:
and the error message is "'show_popup_div' is undefined"
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=unicode" />
<script type="text/javascript">
function show_popup_div() {
var imageDiv=document.getElementById("image_div");
var switchA=document.getElementById("switch_a");
imageDiv.style.display='block';
}
async function hide_popup_div() {
var imageDiv=document.getElementById("image_div");
await sleep(5000);
imageDiv.style.display='none';
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
</script>
</head>
<body>
<a id="switch_a" onmousemove="show_popup_div()" onmouseout="hide_popup_div()">click me to open a image</a>
<div id="image_div">
<img id="image" src="http://www.rd.com/wp-content/uploads/sites/2/2016/02/06-train-cat-shake-hands.jpg" usemap="#map1"/>
</div>
</body>
How can i fix this? Thank you.
Upvotes: 0
Views: 1158
Reputation: 1030
I believe the Promise function is not compatible with IE at all without a Javascript Library as mentioned by Jaromanda X. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
Upvotes: 2
Reputation: 155718
You don't need JavaScript for this effect, you can use pure CSS using the :hover
pseudo-class and the +
adjacent-element selector:
#image_div {
display: none;
}
#switch_a:hover + #image_div {
display: block;
}
Upvotes: 1