0

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.

Amaan Iqbal
  • 761
  • 2
  • 9
  • 25
qwer11121
  • 138
  • 2
  • 15
  • Possible duplicate of [How to make promises work in IE11](https://stackoverflow.com/questions/36016327/how-to-make-promises-work-in-ie11) – Evan Trimboli Aug 07 '17 at 01:22
  • 1
    IE11 does not support the `async` / `await` syntax. It only supports ECMAScript 5 and some ECMAScript 6 features. – Dai Aug 07 '17 at 01:24

2 Answers2

2

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

Moe-Joe
  • 1,012
  • 3
  • 15
  • 27
  • 1
    Correct. Promises are a much newer technology than IE 11. I would suggest using setTimeout instead. – Michael Thompson Aug 07 '17 at 01:25
  • 1
    This answer is very misleading, it's not the use of Promises that is the issue, as IE11 **can** use Promises with an appropriate library. However, async/await and arrow notation => can not be supported in IE11 as this is a syntax change in javascript, rather than a lack of "built-in" functionality – Jaromanda X Aug 07 '17 at 01:45
1

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;
}
Dai
  • 141,631
  • 28
  • 261
  • 374