[Solved] if window.location.href.indexOf(‘player=1’) add style [closed]


You need to set the style of the body element if the string you are checking for is present in the URL.

if(window.location.href.indexOf("player=1")!=-1)
    document.body.style.backgroundColor="#000";

Alternatively, to avoid setting inline styles, you can create a new class and apply it to the body if the string you are checking for is present.

body.player1{
    background:#000;
}

if(window.location.href.indexOf("player=1")!=-1)
    document.body.classList.add("player1");

solved if window.location.href.indexOf(‘player=1’) add style [closed]