What causes the error "Can't execute code from a freed script"

Viewed 93062

I thought I'd found the solution a while ago (see my blog):

If you ever get the JavaScript (or should that be JScript) error "Can't execute code from a freed script" - try moving any meta tags in the head so that they're before your script tags.

...but based on one of the most recent blog comments, the fix I suggested may not work for everyone. I thought this would be a good one to open up to the StackOverflow community....

What causes the error "Can't execute code from a freed script" and what are the solutions/workarounds?

12 Answers

You get this error when you call a function that was created in a window or frame that no longer exists.

If you don't know in advance if the window still exists, you can do a try/catch to detect it:

try
{
  f();
}
catch(e)
{
  if (e.number == -2146823277)
    // f is no longer available
    ...
}

This error can occur in MSIE when a child window tries to communicate with a parent window which is no longer open.

(Not exactly the most helpful error message text in the world.)

The explanations are very relevant in the previous answers. Just trying to provide my scenario. Hope this can help others.

we were using:

<script> window.document.writeln(table) </script>

, and calling other functions in the script on onchange events but writeln completely overrides the HTML in IE where as it is having different behavior in chrome.

we changed it to:

<script> window.document.body.innerHTML = table;</script> 

Thus retained the script which fixed the issue.

Related