Showing posts with label chrome. Show all posts
Showing posts with label chrome. Show all posts

Friday, July 5, 2013

Origin null is not allowed by Access-Control-Allow-Origin Chrome fix

When working on simple html prototypes that don't really need a backend server (Single page app prototypes). You often need to load html / js files from disk. This is disallowed for your protection by default and you will get errors like:

Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. file:///D:/asdf.html
XMLHttpRequest cannot load file:///D:/asdf.html. Origin null is not allowed by Access-Control-Allow-Origin. 

Simple solution for chrome: Start with --allow-file-access-from-files option :

chrome --allow-file-access-from-files

Thursday, June 6, 2013

Inspect all the event handlers on a DOM Element


Here’s how chrome Developer Tools make it super simple. Just inspect an element and look inside the Event Listeners section as shown:


Expand any event and you can see what element level the event is handled on e.g. here blur is handled on document as well as the div:

You can even jump to the function body (this is a minified file so it’s all on line 1) by clicking on the filename

As an aside: there is no way to do this in your own code http://stackoverflow.com/a/2623352/390330

Saturday, April 20, 2013

Webstorm Error : XMLHttpRequest cannot load file. Origin null is not allowed by Access-Control-Allow-Origin

This happens because XMLHttpRequest is not allowed by default in any web browser when running off the local file system.

One way around that is to run in a web server but for simple quick scripts that might be an overkill.

Here's how you can run your site in webstorm without a web server: 

There is a simple flag --allow-file-access-from-files you can set in Chrome to overcome this. Go to your settings:
Then Web Browsers and click on Settings button next to chrome:
Put in the flag and get cracking:
Make sure you have all instances of chrome closed before you start a debug session because the command line flag will only work on a fresh launch of the browser.

Update: or you could always use (for webstorm 6+) : http://localhost:63342/Your_Project_Name which is the built-in web server inside WebStorm.

See how to do it here: