0

What are the properties for a tab that have the same values for every tabs in a tabbed browser window?

For example, If you have 1 window with 3 tabs open, then the tabs' 3 urls [window.location.href/document.location.href] and/or titles [document.title] may or may not be the same.

But if you have another window with 2 tabs, then these 2 tabs will have similar common property with the same value but not the same as the previous 3 tabs.

Is there any common property that each tab has/shares that has the same value for all the tabs in the browser window and can be get/set by javascript or jquery? In browser extension, you can find the id of the browser window which is the same for all the tabs in that window; I need something similar but using javascript or jquery.

Ali007
  • 648
  • 1
  • 12
  • 20
  • 1
    You cannot get at the tabs of a browser using JavaScript except for the tabs you opened yourself using script – mplungjan Dec 04 '13 at 07:07
  • 2
    This sounds like an X-Y problem. What are you trying to achieve? – Quentin Dec 04 '13 at 07:07
  • I need to uniquely identify these 3 tabs or 2 tabs as separate set of tabs in a browser window. i.e. 3 tabs = ID1 or Value1, 2 tabs = ID2 or Value2. – Ali007 Dec 04 '13 at 07:15
  • In browser extension, you can find the id of the browser window which is the same for all the tabs in that window; I need something similar but using javascript or jquery. – Ali007 Dec 04 '13 at 07:26

2 Answers2

1

Javascript sandbox doesn't give you that information. Most similar answers recommend using LocalStorage or cookies to manage different tabs manually

If you have one "Main" window you can manage the others using their window.name ie

var childWindow = window.open('http://localhost/yoursite.html', 'window1');

...

childWindow.close()

in new tab or window

window.name === 'window1'

this allows you to keep references to other tabs, i dont know if this might help you achieve your goals?

Community
  • 1
  • 1
actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
  • I don't need to get the hrefs of all tabs [that will be security/privacy violation], just a way to identify the set of tabs in a browser window. In browser extension, you can find the id of the browser window which is the same for all the tabs in that window; I need something similar but using javascript or jquery. – Ali007 Dec 04 '13 at 07:22
  • 1
    That would be a security violation too – mplungjan Dec 04 '13 at 08:39
  • I understand, but I just need some value that can be used to distinguish a set of tabs from another set of tabs within any window; i.e. distinguish the windows somehow. One solution can be to use "window.outerWidth" which is the same for every tabs in that window. Is there any other value that can be used? – Ali007 Dec 10 '13 at 14:06
0

I found one somewhat solution using "window.outerWidth" but am looking for a better one.

You can use the "window.outerWidth" value as an ID to identify the set of tabs for the specific window (i.e. 3 tabs) that will be the same for all the tabs for that browser window.

But for another window (i.e. 2 tabs) "window.outerWidth" value will be different from the first window but will be the same for the 2 tabs within that browser window. But if the windows are maximized or have same "window.outerWidth" then this will not work.

Any better suggestions?

Ali007
  • 648
  • 1
  • 12
  • 20