궁금증 연구소

안녕하세요. 궁금증연구소입니다.

오늘 포스팅 주제는 "vendor.js:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received 에러"입니다.

 

 

에러 메세지

간단한 버튼 클릭 이벤트 처리를 하려고 하는데 위와 같은 메시지가 떴다.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="code.css">
    <title>이벤트와버튼</title>
    <script src="code.js"></script>
</head>
<body>
    <input id="myBtn" type="button" value="click!" >
</body>
</html>

원인은 script 태그의 위치 때문이다. 바디 태그 최하단으로 옮긴 후 정상 작동한다.

 

스크립트 태그 위치 변경

참고자료는 스택 오버 플로우의 다음 글이다.

https://stackoverflow.com/questions/9778888/uncaught-typeerror-cannot-set-property-onclick-of-null

 

Uncaught TypeError: Cannot set property 'onclick' of null

I'm having problems making my window alert pop up with a simple checkbox and can't for the life of me figure out why. Here's the basic Javascript and HTML: var blue_box=document.getElementById("

stackoverflow.com

 

원인

아마도 이분의 정보에 따르면, 자바스크립트의 js 파일이 요구하는 명령을 수행하려는  요소가 로드되기 전에 자바스크립트를 위치시켜서 인 것 같다.

반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading