How to make a custom url for a file in electron

88
September 16, 2021, at 3:30 PM

I am trying to build a mini browser using Electron.js. Is it possible to make urls like chrome://settings or about:config, so that when the user goes to that link I can show an html file? I basically want to associate a url with a file in electron.

Answer 1

You could use Data URIs, and base64-encode the contents of your data as a link. You can use Javascript to encode and decode binary data, then you just specify the MIME type at the start.

If you go to the following URL in a browser for example you'll see a png decoded and rendered:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==

The MDN Web doc in the first link mentions the process of base64 encoding an HTML file.

Alternatively, if you just want to force the download of a link you could add the download attribute to your anchor.

READ ALSO
Renaming and versioning image uploads in php

Renaming and versioning image uploads in php

So I have an image upload page in my forumIf an image already exists, the old version is renamed to file

72
Log4j Dependecy Project NOT READING Properties File

Log4j Dependecy Project NOT READING Properties File

So I have a main spring-boot project that has 2 other projects (not spring) as dependency

68
Uncaught ReferenceError: addAdresar is not defined at HTMLInputElement.onclick

Uncaught ReferenceError: addAdresar is not defined at HTMLInputElement.onclick

I created a modal popup with grid columnsThis works well, my data is loaded into the grid

45