Set Background to different color for management pages

Is there a way with Javascript to change the background color based on if a user is logged in?

I want a different background color for the management pages. I can do this with JavaScript and changing the background for all of the scenes that need it, but I need a better way. 

Currently, if the page is refreshed, it goes to the default background color. 

Wondering if I could base it on if a user is logged in. If a user is logged in, change the background color. If not logged in, leave it as the default color.

 

Thanks

Jason

Hello Sam,

 

sorry currently i don't have that code .

 

Regards,

Sunny Singla

ssingla1985@gmail.com

+919855089359

Hi Sunny,

In my case I just want to change background color only for specific scene, regardless of whether user has logged in or not.

I was to change background to be gradient and not  solid. Please share the javascript code if you can, as I am just a beginner in javascript.

 

Thanks

Sam

Hello San,

 

Yes you can try and set any CSS with in javascript given above .

 

Regards,

Sunny Singla

ssingla1985@gmail.com

+919855089359

Hi Sunny, 

 

Is there a way add a gradient background in javascript??

 

Sam

Yes Possible just check the Role as well 

 

Regards,

Sunny Singla

ssingla1985@gmail.com

+919855089359

Sunny - I want to take this one step further.

On the original post, we are making the background white if a user is logged in. Can we restrict this only to users that have the user role of Admin or Staff?

 

Thanks

Jason

Try this

$(document).on('knack-scene-render.any', function (event, view, records) {
if(Knack.getUserAttributes()!="No user found")
{
$("body").css("background","red");

$("#kn-app-header").show();
}

else

{

$("#kn-app-header").hide();

}
});

That worked great!

I would also like to add, that if a user is not logged in, that the main top header is hidden. 

What would I add in to do that?

Thanks!

Thanks Sunny! I will give that a shot.

Hello Jason,

 

Try below code hope that help 

 

$(document).on('knack-scene-render.any', function (event, view, records) {
if(Knack.getUserAttributes()!="No user found")
{
$("body").css("background","red");
}
});

 

Regards,

Sunny Singla

+919855089359

ssingla1985@gmail.com