2

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
4

1 回答 1

1
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 + ')';
});
于 2013-07-26T07:17:56.310 回答