Internet Explorer: ScriptImports is undefined

Today I spent way too much time on hunting down a bug that occurred in Internet Explorer 11 running our intranet solution on SharePoint Online / 2016. The problem showed itself by throwing the following error in the console:

SCRIPT5009: ‘ScriptImports’ is undefined
File: eval code (453), Line: 37, Column: 29

The referenced “file” pointed to some internal IE code dealing with Ajax calls. After this error had occurred, other (all?) Ajax calls broke until the page reloaded.

I finally tracked it down to happening when clicking a link with an inline JavaScript handler:

<a href="javascript:void(0)" onclick="javascript:myFunction();">Run myFunction</a>

Nothing special at fist sight, but notice href="javascript:void(0)"  that is supposed to simply stop the default browser action when clicking the link. I’ve seend this before and have assumed it is a proper way to do things. Turns out it’s not! Removing it solved the problem. Here are two alternatives that work:

<a href="#" onclick="javascript:myFunction();">Run myFunction</a>

and

<a href="javascript:return false;" onclick="javascript:myFunction();">Run myFunction</a>

This entry was posted in Development and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *