UFO ET IT

"해제 된 스크립트에서 코드를 실행할 수 없습니다"오류의 원인

ufoet 2020. 12. 1. 20:08
반응형

"해제 된 스크립트에서 코드를 실행할 수 없습니다"오류의 원인


나는 얼마 전에 해결책을 찾았다 고 생각했습니다 (내 블로그 참조 ).

JavaScript (또는 JScript 여야 함) 오류 "해제 된 스크립트에서 코드를 실행할 수 없습니다"가 표시되는 경우-스크립트 태그 앞에 오도록 헤드의 메타 태그를 이동해보십시오.

...하지만 가장 최근의 블로그 댓글 중 하나에 따르면 내가 제안한 수정 사항이 모든 사람에게 적용되지 않을 수 있습니다. 나는 이것이 StackOverflow 커뮤니티에 개방하기에 좋은 것이라고 생각했습니다 ....

"해제 된 스크립트에서 코드를 실행할 수 없습니다"라는 오류의 원인은 무엇이며 솔루션 / 해결 방법은 무엇입니까?


더 이상 존재하지 않는 창이나 프레임에서 만든 함수를 호출 할 때이 오류가 발생합니다.

창이 여전히 존재하는지 미리 알지 못하는 경우 try / catch를 수행하여 감지 할 수 있습니다.

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

이 오류는 스크립트의 '부모'창이 삭제되었지만 (예 : 닫힘) 여전히 보유 된 스크립트에 대한 참조 (예 : 다른 창)가 호출 될 때 발생합니다. '객체'는 아직 살아 있지만 실행하려는 컨텍스트는 그렇지 않습니다.

다소 더럽지 만 내 Windows 사이드 바 가젯에서 작동합니다.

일반적인 아이디어는 다음과 같습니다. '메인'창은 일부 코드를 평가하는 기능을 설정합니다. 그러면 '자식'이이 "빌더 함수"(메인 창의 범위에 / 바운드 / 바인딩 됨)를 호출하고 '메인'창에도 바인딩 된 함수를 다시 가져올 수 있습니다. 명백한 단점은 물론 '리바운드'기능이 정의 된 범위를 넘어서 닫을 수 없다는 것입니다.

이것은 부분적으로 의사 코드이지만 Windows 사이드 바 가젯에서 변형을 사용합니다 (사이드 바 가젯이 "무제한 영역 0"에서 실행되기 때문에 시나리오를 크게 변경하거나 변경하지 않을 수 있기 때문에 계속 이렇게 말합니다.)


// This has to be setup from the main window, not a child/etc!
mainWindow.functionBuilder = function (func, args) {
  // trim the name, if any
  var funcStr = ("" + func).replace(/^function\s+[^\s(]+\s*\(/, "function (")
  try {
    var rebuilt
    eval("rebuilt = (" + funcStr + ")")
    return rebuilt(args)
  } catch (e) {
    alert("oops! " + e.message)
  }
}

// then in the child, as an example
// as stated above, even though function (args) looks like it's 
// a closure in the child scope, IT IS NOT. There you go :)
var x = {blerg: 2}
functionInMainWindowContenxt = mainWindow.functionBuilder(function (args) {
  // in here args is in the bound scope -- have at the child objects! :-/
  function fn (blah) {
    return blah * args.blerg
  }
  return fn
}, x)

x.blerg = 7
functionInMainWindowContext(6) // -> 42 if I did my math right

변형으로, functionBuilder 함수가 기본 창 컨텍스트에 정의되어있는 한 기본 창은 functionBuilder 함수를 자식 창에 전달할 수 있어야합니다!

너무 많은 단어를 사용한 것 같습니다. YMMV.


JS 개체에 액세스하려는 경우 가장 쉬운 방법은 복사본을 만드는 것입니다.

var objectCopy = JSON.parse(JSON.stringify(object));

도움이 되길 바랍니다.


이 동작을 본 매우 구체적인 사례가 있습니다. IE6 및 IE7에서 재현 가능합니다.

iframe 내에서 :

window.parent.mySpecialHandler = function() { ...work... }

그런 다음 새 콘텐츠로 iframe을 다시로드 한 후 iframe이 포함 된 창에서 다음을 수행합니다.

window.mySpecialHandler();

mySpecialHandler가 더 이상 종료되지 않는 컨텍스트 (iframe의 원래 DOM)에 정의 되었기 때문에이 호출은 "해제 된 스크립트에서 코드를 실행할 수 없습니다"와 함께 실패합니다. (iframe을 다시로드하면이 컨텍스트가 손상되었습니다.)

You can however safely set "serializeable" values (primitives, object graphs that don't reference functions directly) in the parent window. If you really need a separate window (in my case, an iframe) to specify some work to a remote window, you can pass the work as a String and "eval" it in the receiver. Be careful with this, it generally doesn't make for a clean or secure implementation.


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.)


Beginning in IE9 we began receiving this error when calling .getTime() on a Date object stored in an Array within another Object. The solution was to make sure it was a Date before calling Date methods:

Fail: rowTime = wl.rowData[a][12].getTime()

Pass: rowTime = new Date(wl.rowData[a][12]).getTime()


I ran into this problem when inside of a child frame I added a reference type to the top level window and attempted to access it after the child window reloaded

i.e.

// set the value on first load
window.top.timestamp = new Date();

// after frame reloads, try to access the value
if(window.top.timestamp) // <--- Raises exception
...

I was able to resolve the issue by using only primitive types

// set the value on first load
window.top.timestamp = Number(new Date());

This isn't really an answer, but more an example of where this precisely happens.

We have frame A and frame B (this wasn't my idea, but I have to live with it). Frame A never changes, Frame B changes constantly. We cannot apply code changes directly into frame A, so (per the vendor's instructions) we can only run JavaScript in frame B - the exact frame that keeps changing.

We have a piece of JavaScript that needs to run every 5 seconds, so the JavaScript in frame B create a new script tag and inserts into into the head section of frame B. The setInterval exists in this new scripts (the one injected), as well as the function to invoke. Even though the injected JavaScript is technically loaded by frame A (since it now contains the script tag), once frame B changes, the function is no longer accessible by the setInterval.


I got this error in IE9 within a page that eventually opens an iFrame. As long as the iFrame wasn't open, I could use localStorage. Once the iFrame was opened and closed, I wasn't able to use the localStorage anymore because of this error. To fix it, I had to add this code to in the Javascript that was inside the iFrame and also using the localStorage.

if (window.parent) {
    localStorage = window.parent.localStorage;
}

got this error in DHTMLX while opening a dialogue & parent id or current window id not found

        $(document).ready(function () {

            if (parent.dxWindowMngr == undefined) return;
            DhtmlxJS.GetCurrentWindow('wnManageConDlg').show();

});

Just make sure you are sending correct curr/parent window id while opening a dialogue


On update of iframe's src i am getting that error.

Got that error by accessing an event(click in my case) of an element in the main window like this (calling the main/outmost window directly):

top.$("#settings").on("click",function(){
    $("#settings_modal").modal("show");
}); 

I just changed it like this and it works fine (calling the parent of the parent of the iframe window):

$('#settings', window.parent.parent.document).on("click",function(){                    
   $("#settings_modal").modal("show");      
});

My iframe containing the modal is also inside another iframe.


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.

참고URL : https://stackoverflow.com/questions/83132/what-causes-the-error-cant-execute-code-from-a-freed-script

반응형