background image for a webpage

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%;}}

 
[/code]

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

[quote=132591:@Heinz Wieczorek]Now my question is if there is another solution?
[/quote]

Place an Image Well on the WebPage under the other controls, make it the size shown in the IDE, and lock it on all sides in the inspector. Then drag the picture in the project, and set it as picture to the Image Well in Behavior, and make AlignHorizontal Center and AlignVertical Middle.

thank you for the hint.
This works but I see a little problem when resizing the browser… the background image doesn’t scale correctly.
However this is acceptable for me… and it works with IE 11 :slight_smile:

[quote=132710:@Heinz Wieczorek]thank you for the hint.
This works but I see a little problem when resizing the browser… the background image doesn’t scale correctly.
However this is acceptable for me… and it works with IE 11 :-)[/quote]

If you want to scale the picture to the dimensions of the webpage, you can do so by using a Canvas instead and use DrawPicture to display it at scale in the Paint event.