How to change background image (margin image) through script when entering a room
AccioOllie
28 Jul 2022, 07:28I'm trying to change the background image/margin image when I load a new room.
I've tried doing what it says in the documentation:
JS.setCss("#gameBorder", "background-image:url(" + GetFileURL("space.png") + ");")
And then I replaced #gameBorder to body:
JS.setCss("body", "background-image:url(" + GetFileURL("space.png") + ");")
However, neither of these js script commands set the CSS for the background image, for either the body tag or the #gameBorder id.
I did try changing the background-color on the body, and it worked, but for some reason, the background-image property does change at all.
Help?
Pertex
28 Jul 2022, 12:42You can try this
JS.eval("$('body').css('background-image', 'url(" + GetFileURL("space.png") + ")');")
mrangel
28 Jul 2022, 13:24(The reason for this problem is that the setCss
function doesn't work with values containing a colon, such as URIs)

DarkLizerd
28 Jul 2022, 23:41Just guessing, but try this...
Change the background in the UI, then switch to code view, find the command that changes the background, and edit that to the picture you want.
It may be easier to try this with a new game with nothing else added.

Jennifer Wren
29 Jul 2022, 20:39Thank you for the switching to code view advice! I think I might try that, myself, with crossed fingers, at any rate.
AccioOllie
03 Aug 2022, 23:15Sorry for the late response, but I will try all of those answers. Thank you!