/* * This script is used to provide feedback if the demo is not working correctly on the local file system due to the same origin policy. */ (function() { var msg = null; var msgTemplate = '
' + '

SVGInject not working correctly

' + '

Don\'t worry: It\'s most likely because you are running this on your local file system.

' + '

SVGInject works very well in any browser when run with a web server.

' + '

Due to the same origin policy for some browsers (Chrome, Safari), SVGs can not be loaded when run on the file system.

' + '

How to get this to work:

' + '' + '

There are also other possible solutions (--allow-file-access-from-files flag in Chrome) you might want to look for to run this example on the file system.

' + '
'; function createElementFromHTML(htmlString) { var div = document.createElement('div'); div.innerHTML = htmlString; return div.firstChild; } function showMessage() { msg = createElementFromHTML(msgTemplate); document.body.insertBefore(msg, document.body.firstChild); } var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { // readyState is DONE var status = req.status; if (status == 200) { // request status is OK } else { showMessage() } } }; var script = document.querySelectorAll("script[src$='xhr-check.js']")[0]; req.open('GET', script.getAttribute('src'), true); req.send(); })();