简体   繁体   中英

How to run javascript code only from single page among all opened pages

I've a Javascript file getting loaded in each page request which contains some timer based ajax functions.

What I want is that whenever a new site page is opened it should check if any other existing page is already executing those functions so that it can skip execution them. However if "other" page is closed then it should start executing those.

So the pages look like : example.com/page1.htm, example.com/page2.htm -- all on the same site containing the same Javascript file on separate tabs or windows. Not on Iframes. Even same page can be open in multiple tabs or windows.

What is the way to do it?

I tried Googling this but couldn't find any answers to this.

There are several ways to do cross-tab communication but they are all limited to the Same Origin Policy

They are:

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