最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google chrome - Javascript file loading twice - Stack Overflow

programmeradmin3浏览0评论

I am having a strange problem in Google Chrome. I am including a js file via script src tag. I place alert('test') in the file and when I load the page in Chrome, It alerts twice. In every other browser it alerts once. Is there any known cause for this?

Here is the code that loads the JS:

<script type="text/javascript" src="/js/main.js"></script>

It appears this happens in Safari as well. Does not occur in IE and firefox.

I am having a strange problem in Google Chrome. I am including a js file via script src tag. I place alert('test') in the file and when I load the page in Chrome, It alerts twice. In every other browser it alerts once. Is there any known cause for this?

Here is the code that loads the JS:

<script type="text/javascript" src="/js/main.js"></script>

It appears this happens in Safari as well. Does not occur in IE and firefox.

Share Improve this question edited Jun 21, 2018 at 8:20 atw 5,84010 gold badges42 silver badges66 bronze badges asked Jun 14, 2011 at 0:19 JohnJohn 611 gold badge1 silver badge3 bronze badges 11
  • 3 please post the code that loads the javascript – castis Commented Jun 14, 2011 at 0:20
  • 1 Add debugger; to the beginning of your javascript code and then step-through setting break points in the Dev Tool. – Colin Commented Jun 14, 2011 at 0:23
  • Ok I did that and it seems to go over the same code twice as I keep clicking "step into next function call". It read from line 0 to the last line then goes back to 0 after the last line. After the second time going down the script it stops. – John Commented Jun 14, 2011 at 0:26
  • 1 can you post the code from main.js? – Jeff Commented Jun 14, 2011 at 0:33
  • 1 If you found the solution yourself, please post it as an answer and accept it in a few days. That way those that have the same problem in the future will know what to do. – Nzall Commented Jun 24, 2014 at 14:43
 |  Show 6 more ments

3 Answers 3

Reset to default 12

I had this recently and eventually found out it was a chrome extension, specifically the cache killer extension

This might be helpful

Webkit browsers (Chrome, Safari) are loading pages redirected from .htaccess twice!

I've noticed this same problem in Chrome. I have some code that runs when the page loads and I have an alert inside that code. In every browser other than Chrome this code is run once, thus the alert displays once. In chrome the alert shows twice. I am not doing anything special, just running code when the onload event is triggered within <body onload="somefunction()">. I am not using links, iframes, or the Cache Killer extension. I tested it in Safari and the code is only being called once. This seems to be a Chrome specific problem.

I did some research and it appears this is a bug with Chrome. I found this link https://code.google./p/chromium/issues/detail?id=64810

Depending on your specific situation, this page may give you a work around for the problem.

The problem does not seem to be fixed as of yet.

发布评论

评论列表(0)

  1. 暂无评论