Hello,
I need to set a background image to a webpage.
I’ve found an example here:
(https://forum.xojo.com/6214-body-background-tag/0)
While this works this example uses a static URL to the background image.
But using WE I didn’t know how to use a URL to a picture on local disk on my WE server, for example to c:\picture\test1.jpg
To my understanding such a URL must be a non-static=dynamic (webfile URL)
So after some experiments I’ve found that I can do this using a webfile and a pageSource control’s “editSource” event…
Basically what I do is to put the following code in a variable “source_background”
[code]#bckg {background:url(“theURL”);
no-repeat center center;min-height:100%;background-size:cover;}
body{min-height:100%;}}
Where “theURL” is a placeholder that will be replaced later.
Then I create a webfile for the image that I want to use in the PageSource EditSource Event:
[code]dim f as folderitem
dim mySource as String
f=getfolderitem (“c:\picture\test1.jpg”)
app.mywebfile = webFile.Open(f) 'this will create a URL to the picture: app.mywebfile.url
app.mywebfile.MIMEType = “application/octet-stream”
app.mywebfile.ForceDownload = false
mySource = Replace(source_background,“theURL”,app.mywebfile.url) 'replace placeholder with webfile URL
source = mySource 'set ByRef Variable “source”[/code]
Now my question is if there is another solution?
I think that it would be possible - and maybe better - to use Javascript for this purpose?
But how would I create a URL (at runtime) to the image on my WE Server in a JavaScript function?
Another problem I have is that IE10 says “Please enable javascript” or “unsupported browser” (depending if CompatibiliytMode is on or off…)
IE 11 doesn’t show an error - but it doesn’t display the background image… just a blank webpage.
Maybe IE10/11 would would work with a Javascript solution…?
It would be important that it works with current versions of IE.
(Firefox and Chrome both work)
Heinz