简体   繁体   English

Opera:.js文件无法加载

[英]Opera: .js file won't load

I have a page that calls a script in the header, like so: 我有一个页面在标题中调用脚本,如下所示:

<script type="text/javascript" src="http://www.discoverfire.net/analytics/l/a.js"></script>

(Note you will NOT be able to load this script as it is DNSd locally as a staging domain) (请注意,您将无法加载此脚本,因为它是本地DNSd作为暂存域)

Very Simple. 很简单。

Firefox, IE, Chrome all have no problem with this basic, square-one feature. Firefox,IE,Chrome对此基本的平方一功能都没有问题。

Opera, however, refuses to load the script. 但是,Opera拒绝加载脚本。 Any variables or functions in it are "undefined" and in dragonfly, the script tag is shown in the DOM, but the "Script" tab says "No script files found." 其中的任何变量或函数都是“未定义的”,在蜻蜓中,脚本标记显示在DOM中,但是“脚本”选项卡显示“未找到脚本文件”。

I go to google and find random pages, their external .js files seem to work just fine. 我去谷歌,找到随机的页面,他们的外部.js文件似乎工作得很好。

Any idea why Opera hates me? 知道为什么Opera讨厌我吗? Is there a security/javascript thing I am missing? 我缺少安全性/ JavaScript吗?

A few things that may be relevant, but really should make no difference: 一些可能相关的事情,但实际上应该没有任何区别:

  • The script is on a different domain than the page. 该脚本与页面位于不同的域中。
  • The script is only available on my local network. 该脚本仅在我的本地网络上可用。 The domain is DNS'd locally for staging, from outside the network it points somewhere else. 该域名从本地网络通过DNS指向本地进行登台。 Does Opera have a setting to secretly use an external DNS server? Opera是否设置了秘密使用外部DNS服务器的设置?
  • The script works on every other browser I have. 该脚本可在我拥有的所有其他浏览器上使用。
  • The problem isn't in the script content. 问题不在于脚本内容。 I've reduced it to a single line with an alert and it simply won't work in Opera. 我已将其缩小为带有警报的一行,并且它根本无法在Opera中使用。

Update: 更新:

OK, the problem seems to be how Opera treats the domain. 好的,问题似乎在于Opera如何处理域名。

I have moved the script to several other domains, and it DOES work just fine. 我已将脚本移至其他几个域,并且确实可以正常工作。 I've moved it to several paths on the locally DNS'd domain, and it won't work from anywhere on that domain. 我已将其移至本地DNS域名上的多个路径,并且该域名上的任何地方都无法使用。

This leads me to believe that the problem is that Opera can't, or won't, load the script from this domain for some reason. 这使我相信问题是Opera由于某种原因无法或不会从该域加载脚本。

Strangely, there seems to be no problem loading pages and other resources from the domain, the problem lies in .js files only. 奇怪的是,从域中加载页面和其他资源似乎没有问题,问题仅在于.js文件。

The domain is registered, but parked. 该域已注册,但已寄存。 We DNS'd it locally so we can use it for staging/testing, and that may be messing with Opera somehow with JS security. 我们在本地对其进行DNS编码,因此我们可以将其用于登台/测试,并且这可能与Opera在某种程度上与JS安全有关。

I could be wrong though - I really have no idea. 我可能是错的-我真的不知道。 If anyone else has one, I'd love to hear it. 如果其他人有一个,我很想听听。

Update 2: 更新2:

Regarding Dragonfly and the error console/developer tools, they don't say anything about the script at all. 关于Dragonfly和错误控制台/开发人员工具,他们根本没有提及脚本。 There are plenty of Undefined Variable errors for variables and functions that should be present from the script, but other than that, no errors. 脚本中应该存在大量的变量和函数未定义变量错误,但除此之外,没有错误。 Oddly, the script tag does show up in the DOMM, but if I click on the Scripts tab, it says "No Scripts Found". 奇怪的是,脚本标签确实显示在DOMM中,但是如果我单击“脚本”选项卡,它会显示“未找到脚本”。

Update 3: 更新3:

There is no blocked content, so we can at least rule out that setting. 没有被阻止的内容,因此我们至少可以排除该设置。

You may want to see if its ad blocker is getting in the way. 您可能想查看其广告拦截器是否挡住了路。 Your URL contains the text "analytics," which may be part of a "block this" pattern. 您的URL包含“分析”文本,该文本可能是“阻止此”模式的一部分。 I know some block Google analytics through Opera. 我知道有些人通过Opera阻止了Google分析。 An easy test for this may be to try moving your .js to a different path on the host. 一个简单的测试可能是尝试将.js移到主机上的其他路径。

Have you checked Opera's error console? 您是否检查过Opera的错误控制台? Tools > Advanced > Error Console It should provide information on why it won't load or if there another error of some kind. 工具>高级>错误控制台它应提供有关为何无法加载或是否存在其他某种错误的信息。

Like Jacob suggested, you should check if it isn't blocked. 像Jacob所建议的那样,您应该检查它是否被阻止。 To do this: 去做这个:

  • Right-click on your page 右键单击您的页面
  • Select "Block Content..." in the context menu 在上下文菜单中选择“阻止内容...”
  • At the top of the screen, click the "Details..." button 在屏幕顶部,单击“详细信息...”按钮
  • You should see the URL's that are blocked on the current page 您应该会在当前页面上看到被阻止的网址

You should ask in the Opera Forums. 您应该在Opera论坛中提问。 I had some problems with Opera in the past and they answered quickly. 过去我在Opera上遇到过一些问题,他们很快就回答了。

Is the host serving the correct mime type of the JavaScript file. 主机是否为JavaScript文件提供了正确的mime类型。 It's not a commonly known fact but the type=text/javascript attribute is actually ignored by browsers as it trusts that the server is specifying the correct type. 这不是一个众所周知的事实,但是浏览器实际上会忽略type=text/javascript属性,因为它相信服务器正在指定正确的类型。

Additionally the mime type of text/javascript is actually wrong when it comes to JavaScript, the actual JavaScript mime type is application/ecmascript (if I recall correctly, it may be application/javascript though). 另外,当涉及到JavaScript时, text/javascript的mime类型实际上是错误的,实际的JavaScript mime类型是application/ecmascript (如果我application/ecmascript话,它可能是application/javascript )。 If you don't believe me you should have a look here where I had more information and linked off to the Douglas Crockfords videos where he discussed the mime type. 如果您不相信我,可以在这里查看更多信息,并链接到道格拉斯·克罗克福德(Douglas Crockfords)的视频,他在视频中讨论了哑剧类型。

I had something similar recently - opera would just not run a script on an external server... nor if I downloaded it and had it on localhost. 我最近有类似的事情-Opera不会在外部服务器上运行脚本...也不会下载并在本地主机上运行它。 It only ran when copy/pasted between script tags into the html page. 仅在脚本标记之间复制/粘贴到html页面中时才运行。

It turned out that the script was encoded with UTF-16 and that was somehow confusing the browser. 事实证明,脚本是用UTF-16编码的,这在某种程度上使浏览器感到困惑。 When I converted it to UTF-8, everything ran fine. 当我将其转换为UTF-8时,一切运行正常。

So, just in case and if you still have that problem, check out the encoding settings... 因此,以防万一,如果仍然有问题,请检查编码设置...

I had the exact same issue, tying to load a script from a localhost/development server into a page, hosted on the public server at no avail. 我遇到了完全相同的问题,试图将脚本从本地主机/开发服务器加载到页面中,但无济于事,该页面托管在公共服务器上。 The only way I managed the script to load in Opera was to save a copy of the page into a location on the same development server and use the tag to refer to the original domain to get the page's .css and .js linked files. 我管理脚本在Opera中加载的唯一方法是将页面的副本保存到同一开发服务器上的某个位置,并使用标记引用原始域来获取页面的.css和.js链接文件。 That worked. 那行得通。 Looks like Opera doesn't like to mix public and localhost domains, but handles localhost without complaints. 看起来Opera不想混合使用公共域和本地主机域,但是可以处理本地主机而不会抱怨。

what you're seeing is probably Opera's security precaution against the so-called "phish pharm" attacks: cross-network protection. 您所看到的可能是Opera针对所谓的“网络钓鱼骗局”攻击的安全预防措施:跨网络保护。 You can not mix content from a public server and content from a local server. 您不能混合来自公共服务器的内容和来自本地服务器的内容。

Have a look at my answer here for a workaround: 请在这里查看我的答案以找到解决方法:

Opera won't load some JavaScript files Opera不会加载一些JavaScript文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM