Opera: .js file won't load

2019-08-03 22:47发布

问题:

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)

Very Simple.

Firefox, IE, Chrome all have no problem with this basic, square-one feature.

Opera, however, refuses to load the script. 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."

I go to google and find random pages, their external .js files seem to work just fine.

Any idea why Opera hates me? Is there a security/javascript thing I am missing?

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. Does Opera have a setting to secretly use an external DNS server?
  • 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.

Update:

OK, the problem seems to be how Opera treats the domain.

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.

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.

Strangely, there seems to be no problem loading pages and other resources from the domain, the problem lies in .js files only.

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.

I could be wrong though - I really have no idea. If anyone else has one, I'd love to hear it.

Update 2:

Regarding Dragonfly and the error console/developer tools, they don't say anything about the script at all. 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".

Update 3:

There is no blocked content, so we can at least rule out that setting.

回答1:

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. I know some block Google analytics through Opera. An easy test for this may be to try moving your .js to a different path on the host.



回答2:

Have you checked Opera's error console? Tools > Advanced > Error Console It should provide information on why it won't load or if there another error of some kind.



回答3:

Like Jacob suggested, you should check if it isn't blocked. 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


回答4:

You should ask in the Opera Forums. I had some problems with Opera in the past and they answered quickly.



回答5:

Is the host serving the correct mime type of the JavaScript file. 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.

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



回答6:

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. It only ran when copy/pasted between script tags into the html page.

It turned out that the script was encoded with UTF-16 and that was somehow confusing the browser. When I converted it to UTF-8, everything ran fine.

So, just in case and if you still have that problem, check out the encoding settings...



回答7:

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. That worked. Looks like Opera doesn't like to mix public and localhost domains, but handles localhost without complaints.



回答8:

what you're seeing is probably Opera's security precaution against the so-called "phish pharm" attacks: cross-network protection. 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