Juffin
Juffin

Reputation: 57

Specific URL's on Window.Onload

i'm fairly newbie in JS, just learning so don't bash me hard if i say something unorthodox.

Aim

Load specific background image when user enters specific topic on forum

What I've tried

I searched some options and found Window.Onload option that would allow me to load image on background after page loading is complete. The question is how do i trigger specific images on specific topics?

Pseudo Code

if (user enters) /t/sueper-topic
load - super-background.png
else - carry on

Upvotes: 2

Views: 569

Answers (1)

karaxuna
karaxuna

Reputation: 26940

var pathImages = {
     '/t/sueper-topic': 'super-background.png'
};

window.addEventListener('load', function(){
    var src = pathImages[location.pathname];
    if(src)
        document.body.style.backgroundImage = 'url(' + src + ')';
});

Upvotes: 1

Related Questions