How to use js to determine whether the current page is a specified link, and whether the user is on the PC side or the mobile side to jump to a different home page?

I have read the website and many of the answers are only to jump on the PC side and the mobile side. But I want to put this js in the head, in that case, every time I visit another page, I will perform the js jump back to the home page, so it won"t achieve the effect I want. What I want is to judge whether the current page is xxx.html first? If yes, continue to determine the PC side and the mobile side to jump to different home pages, if not, do not execute. Could you tell me how to write this js?

Mar.01,2021

can't you just put the judgment logic in xxx.html ? The rest of html will not execute this logic


what I want is to determine whether the current page is xxx.html first?

like this?

if(location.href == xxx.html){
    //xxx.html
} else {

}
Menu