Accessing relative URL's via “ajax” from “file://” content

前端 未结 2 1522
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 02:55

I\'m putting together some demo pages, and one of the things I want to demonstrate involves fetching HTML fragments dynamically with subsequent processing. Thus I\'ve got si

相关标签:
2条回答
  • 2020-12-07 03:31

    Had the same issue in Safari+Firefox:

    The alert in code below does not run:

    $.getScript('script.js', function () { alert("Script loaded and executed."); })

    Loading an external file instead of script.js will run.

    0 讨论(0)
  • You can add --allow-file-access-from-files to the command line when launching chrome to disable this security feature :)

    Is it a bug? Maybe, maybe not, what's happening is it's not treating file:// as a single domain, requests to a different file are treated as a different domain and therefore blocked by the SOP rules. It's a choice by the Chrome/Chromium developers, whether it's the correct one depends on your point of view I suppose.

    There's a lot of dicusssion on this in the Chrome issues section on Google code, you may find the discussion of interest, here and here.

    0 讨论(0)
提交回复
热议问题