XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)

前端 未结 9 907
醉梦人生
醉梦人生 2020-11-22 03:30

I\'m trying to create a website that can be downloaded and run locally by launching its index file.

All the files are local, no resources are used online.

Wh

9条回答
  •  轮回少年
    2020-11-22 04:02

    The way I just worked around this is not to use XMLHTTPRequest at all, but include the data needed in a separate javascript file instead. (In my case I needed a binary SQLite blob to use with https://github.com/kripken/sql.js/)

    I created a file called base64_data.js (and used btoa() to convert the data that I needed and insert it into a

    so I could copy it).

    var base64_data = "U1FMaXRlIGZvcm1hdCAzAAQA ... AhEHwA==";
    

    and then included the data in the html like normal javascript:

    I imagine it would be trivial to modify this to read JSON, maybe even XML; I'll leave that as an exercise for the reader ;)

提交回复
热议问题