I have a zip file located at http://my-website.com/user-site.zip
. This zip file contains a bunch of html, css and javascript files that, when extracted, look something like this (exact contents unknown):
index.html
js/
script.js
css/
style.css
I want to be able to view this webpage in, e.g., an iframe, after downloading it in-browser.
Right now my approach looks like this:
createObjectUrl
(explained here) to create urls for each of these assets.index.html
. This almost works, except for one problem. The urls generated by createObjectUrl
are pretty much random, so index.html
can't resolve references to other resources. How can I get around this?
Right-click on the zip file and click on the option "Extract file with a specified folder. Select the Folder that you just made. Open that folder with VS-Code.
To unzip the your split zipped library with The Unarchiver, you can right-click on the first file “. zip. 001”, hover over “Open With” and select The Unarchiver and it will automatically begin unzipping. We thank developers for this non-sense confusion, hope this article helps.
Very great question! I'm sitting here pondering this myself now! One thing that you could do is create a JavaScript object/array to "map" the files and their paths, along with their created object URLs. Then use JavaScript to replace the relative paths with the absolute object URLs. Unless...you can't get the path of the file.
If that is the case, a JavaScript library you may be interested in would be JSZip, which can give you paths for files within a ZIP.
For your map, you could do something like this (after you strip necessary parts from the JSZip path like the root directory):
var map = [
{"relativePath":"css.css","absolutePath":*Object URL Goes Here*}
];
Then loop through each entry in the map and replace every instance of relativePath[x] with the absolutePath[x] in a given file, whether it be the raw text of the file or the innerHTML of the iframe.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With