简体   繁体   中英

Loop Change Page Title JavaScript

So I have this code

 function changeTitle() { var title = document.title; var variable = document.querySelector('.liconspan').innerHTML; console.log(variable) setTimeout(changeTitle, 3000); document.title = title; } changeTitle();

I want to loop changing the title like the following:

"One" > "Two" > "One" > "Two" etc.. just sample texts will be replaced with the text I want and the actual title to loop and change from.

Cheers!

Something like this?

var first = true;
function setTitle()
{
    if(first)
        document.title = "One";
    else
        document.title = "Two";
    first = !first;
}
setInterval(setTitle, 3000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM