3

I wrote some JavaScript to move an ad banner when the user is scrolling. However, it's working fine with every browser except Internet Explorer... It seems like my JS is not even starting... I'm using the latest IE9.

How I'm invoking it:

<html>
<head>
  <script src="./js/move-it.js" type="text/javascript"></script>
</head>
<body>
  ...
  <div id="bird">
    <iframe ...>...</iframe>
  </div>
  <script type="text/javascript">
    start(); // method in move-it.js
  </script>
</body>

Website: http://lolkitten.org

Btw, can anyone tell me how to prevent the banner from crashing into my footer in a nice way? I tried to put a div as "stopper" above the lower ad and use it's "offset-top" attribute, but I guess it always gave me a too small value, i.e. it kept crashing... -.-

Cheers

5
  • I can't see a function called start() anywhere in lolkitten.org/wp-content/themes/lolkitten/js/move-it.js Commented Mar 17, 2012 at 14:39
  • @Matt but, its still running in another web browsers.. Commented Mar 17, 2012 at 14:41
  • @SachinShekhar Yes, which suggests that either it's not moving because of start(), or it is, but start() is in a different file. At the very least, the poster has confused themselves about this function. Commented Mar 17, 2012 at 15:17
  • @Cedric Could you clarify where start() is supposed to be and post the code from within it? Commented Mar 17, 2012 at 15:18
  • Oh, I forgot I had renamed it, and wasn't thinking too much when doing my toy example... It's called launchBird() now, and it's directly after the div#bird containing the ad. Sorry for that... Commented Mar 18, 2012 at 10:13

4 Answers 4

14

I managed to get it to work now. The problem was that IE does not allow const modifiers in JavaScript. I simply changed them to var and it worked finely.

Sign up to request clarification or add additional context in comments.

2 Comments

Why the downvote? IE (at least <= 9) does not get along with const. Try it, and, if you downvote me, please leave a comment! :/
I don't care about those -2 imaginary internet points. It's just that downvoting implies that someone thinks an answer is incorrect, in which case they should explain why this is to enlighten the rest of us. I'm still pretty sure above statement is correct, but if not, I'd really like to know why not and learn about the details.
6

IE, all versions is not tolerant of common errors made by PHP programmers. Here is a list of Javascript syntax not accepted by IE, for all functions, including AJAX:

(These IE Javascript syntax errors are not errors in Opera, Chrome and Firefox.)

  1. you cannot set a default variable value in function declaration parameters function thisFunction(something='x'){ thingy.here;} is not allowed and will read as an undeclared function when thisFunction() is called.

  2. Passing objects as function parameters can have unexpected results: function(someObject) may or may not work depending on the context.

  3. undeclared variables stop the script

  4. event.preventDefault(); cannot be called inside the called function, and will stop the script

  5. event.preventDefault(); must be declared first, in the event reference before all other functions... this is not true on other browsers. So IE must operate asynchronously by default...

    May not be expected when PHP programmers first learn to enjoy the synchronous character of Javascript as lesson #1 in the language. This example does not work (does not work) in the 'a' tag when put directly into the tag of a link

    onclick="function() { 
        if(typeof someFunction === 'function') { 
            event.preventDefault(); 
            someFunction('anyParameter'); 
        };"
    

    When you are using the same code on a page that doesn't implement or declare the function someFunction(). what a waste of time!

  6. onclick='clickChild(this);' doesn't work on IE... and I don't know why. It will actually stop a contained link and nothing will happen. Seems to contradict the above behavior of preventDefault which only works as the first function in an event reference, and if not called first a containing link will be followed. So inconsistent logic in IE. ---as of today, January 21, 2017, in today's Google Chrome update, the above function also does not work in Chrome.

In forms, the 'button' tag does not return the value correctly for form submission. This may be fixed in new IE versions,or it may not be. For my current project: yad1.org the button tag is required for multilingual submission button names that require the same value for all languages.

Conclusion: IE should be removed from Windows and forgotten forever.

Real waste of time debugging. IE needs to get in touch with the programmer friendly world of Javascript.

1 Comment

Can confirm that 1 is true in IE 11 still. What a joke.
0
  1. On the Tools menu, click Internet Options, and then click the Security tab.
  2. Click the Internet zone.
  3. If you do not have to customize your Internet security settings, click Default Level. Then do step 4
    If you have to customize your Internet security settings, follow these steps:

    a. Click Custom Level.
    b. In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section.

  4. Click the Back button to return to the previous page, and then click the Refresh button to run scripts.

Comments

0

A fairly long time later ... same issue on a customer machine with IE11 (Firefox & Edge working fine). The file at (UNC)

file://///server/share/directory/index.html

was loaded correctly, but javascript is not activated.

The solution in this case:

  1. "Internet Options" > Tab "Security" > Zone "Local intranet" > Button "Sites" > Deactivate the third option "Include all network paths (UNCs)" (page reload needed)
  2. "Internet Options" > Tab "Security" > Zone "Trusted sites" > Button "Sites" > Add "file://server" to the Websites (IE restart needed)

Zone Local intranet

Zone Local intranet

Now it works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.