문제

My question is simple,

I have this.

<!DOCTYPE html>
<head>
<script>
window.addEventListener('message', messageHandler, false);
function messageHandler(event)
{
        if(event.data) {
    document.getElementById('test').innerHTML = event.data;
        }

}
</script>
</head>
<body>
<span id="test"></span>
</body>

which returns me this,when it shouldn't return me anything

cf-tick

Why is this? and How can i stop this?

A live example is this: Test Page

올바른 솔루션이 없습니다

다른 팁

You have cloudflare js

http://ajax.cloudflare.com/cdn-cgi/nexp/dok8v=221574e73d/cloudflare.min.js

loaded in your page which posts the message cf-tick. You can see the file posting a message if you search for the following code in the file :

a.postMessage("cf-tick","*")

If you remove the loading of CloudFlare script, no message will be posted to the webpage. If you don't want the cf-tick to get caught in the event listener, you can check if the message is not cf-tick :

window.addEventListener('message', messageHandler, false);
function messageHandler(event){
 if(event.data) {
  if(event.data!="cf-tick")
   document.getElementById('test').innerHTML = event.data;
 }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top