Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript does not work in Internet Explorer 8
    primarykey
    data
    text
    <p>I have a javascript to ask the user to confirm that they want to leave my website. This is how it looks:</p> <pre><code> function confirmLeave() { if(confirm("Do you want to leave my webpage?")) { return true; } else { if(window.event) { window.event.returnValue = false; } else { e.preventDefault(); } return false; } } function initiate () { var links = document.getElementsByClassName("external-link"); for (var i = 0; i &lt; links.length; i++) { links[i].onclick = confirmLeave; } } window.onload = initiate; </code></pre> <p>It works good in Firefox and Chrome but not in IE8. I know that <code>document.getElementsByClassName</code> doesn't work and I tried to remake my code using <code>document.getElementsbyTakeName</code> but haven't got it to work. This is what I came up with:</p> <pre><code>function confirmLeave() { if(confirm("Do you want to leave my webpage?")) { return true; } else { if(window.event) { window.event.returnValue = false; } else { e.preventDefault(); } return false; } } funciton initiate () { if(document.getElementsByClassName) { var links = document.getElementsByClassName("external-link"); for (var i = 0; i &lt; links.length; i++) { links[i].onclick = confirmLeave; } } else { var links = document.getElementsByTagName("external-link"); for (var i = 0; i &lt; links.length; i++) { links[i].onclick = confirmLeave; } } } window.onload = initiate; </code></pre> <p>The <code>external-link</code> is the class I'm using for the links that are to leave my webpage.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload