# Electron.jl - Is there a way to display an html file loaded into a string variable?

**URL:** <https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375>\
**Category:** Web Stack\
**Created:** [April 16, 2018, 9:24pm UTC](https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375 "2018-04-16T21:24:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)\
**Post date:** [April 16, 2018, 9:24pm UTC](https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375/1 "2018-04-16T21:24:50Z")

</div>

I am constructing an html file that I want to display in an electron window. I accumulate the whole html file in a Julia string. I am wondering whether there is a way to display it without first writing it into a file.

For example,

```julia
using Electron
Window(URI("file:///.... "))

```

works.

```julia
Window(str)

```

does not work, where “str” contains the whole html file in one string.

---

<div class="post-metadata">

**Author:** ![jkroso](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkroso/32/220909_2.png) [@jkroso](https://discourse.julialang.org/u/jkroso)\
**Post date:** [April 17, 2018, 9:45am UTC](https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375/2 "2018-04-17T09:45:00Z")

</div>

Yea you can use data URI’s

---

<div class="post-metadata">

**Author:** ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)\
**Post date:** [April 18, 2018, 8:59pm UTC](https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375/3 "2018-04-18T20:59:24Z")

</div>

Thank you for your reply. If I use URI’s as in

```julia
Window(URI(str))

```

I get

```julia
Unexpected start of URL
parse_url(::String) at parser.jl:213
URIParser.URI(::String) at parser.jl:301
include_string(::String, ::String) at loading.jl:522
include_string(::String, ::String, ::Int64) at eval.jl:30
include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at eval.jl:34
(::Atom.##102#107{String,Int64,String})() at eval.jl:82
withpath(::Atom.##102#107{String,Int64,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
hideprompt(::Atom.##101#106{String,Int64,String}) at repl.jl:67
macro expansion at eval.jl:80 [inlined]
(::Atom.##100#105{Dict{String,Any}})() at task.jl:80

```

When I just feed the “str” as follows,

```julia
Window(str)

```

I get a blank window with the correct title and without any errors. As I mentioned in the original post, the “str” written to a file and read back using “URI” function, it displays the content without any problems.

```julia
Window(URI("file:///C:/folder/filename.html"))

```

By the way, the same file written to the “tempdir()” folder does not display the content at all on Windows 10.

---

<div class="post-metadata">

**Author:** ![jkroso](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkroso/32/220909_2.png) [@jkroso](https://discourse.julialang.org/u/jkroso)\
**Post date:** [April 19, 2018, 7:55am UTC](https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375/4 "2018-04-19T07:55:35Z")

</div>

> **[data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)**
>
> The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in Web pages as if they were external resources. It is a form of file literal or here document. This technique allows normally separate elements such as images and style sheets to be fetched in a single Hypertext Transfer Protocol (HTTP) request, which may be more efficient than multiple HTTP requests, and used by several browser extensions to package images as well as other multimedi Th...

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [October 7, 2018, 1:57pm UTC](https://discourse.julialang.org/t/electron-jl-is-there-a-way-to-display-an-html-file-loaded-into-a-string-variable/10375/5 "2018-10-07T13:57:50Z")

</div>

This is perhaps a bit clumsy but works:

```julia
 style = """
<style type="text/css">
table {
border-collapse: collapse;
}
td, th {
border: 1px solid LightGray;
padding: 0.5rem;
text-align: right;
}
</style> \n"""

  #see (characters) https://en.wikipedia.org/wiki/Percent-encoding
  style = replace(style,"\""=>"%22")
  style = replace(style," "=>"%20")

  str = [create a string with the contents of the html table]
  str = string("<html>",style,"<table>",str,"</table></html>")
  str = filter(x -> !isspace(x), str)
  str = string("data:text/html,",str)
  win = Window(URI(str))

```
