Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the content of other tabs in a browser

I am using Mozilla Firefox and I am trying to figure out a way to access the content of other tabs in the same window using JavaScript and the DOM (I am open to other techniques if exist).

E.g., I want to run JavaScript code in tab1 which can find the title of some other tab. Basically I need this so that I can identify a tab which has opened due an href in my current page without using window.open method. All I want is a simple hyperlink which opens a page belonging to the same domain as the current page (the page should be opened in a new tab). Now I want to be able to access this new tab from the current tab.

like image 706
vamyip Avatar asked Jul 08 '10 12:07

vamyip


People also ask

How do I access other tabs?

To open all other recent tabs from another device, -go to the browser, click on the three dots, go to history. -From there you can select “tabs from other devices”, here you see a bigger list. -On that list is another settings with three dots, click that for the option to “open all” tabs.

Can a website view your other tabs?

Modern websites use multiple "event listeners" and can detect every move the user is executing. So, if a user switches the tab or hovers over to another tab, it can gather the data and see whether the user stayed on the web page or not. A website can detect this anomaly by using cookies and IDs.

Can an open browser tab know what other tabs are open in the browser?

Can a website see what other tabs are open? No. None of any website has this kind of feature or advantage to see any other open browser tabs.


3 Answers

Whilst you can easily open a new window using JavaScript, I'm sure that is as far as it goes. From a security point of view you wouldn't want JavaScript in one tab being able to query / access the DOM in another tab. Any site would then be able to gain access to your bank account details, etc. if both sites were opened in separate tabs.

like image 121
Paul Hadfield Avatar answered Oct 16 '22 01:10

Paul Hadfield


You can access the new window/tab if it was opened with JavaScript and the page indeed is in the same domain.

You can open the window/tab like so

var win = window.open("/path_to_page");

Then you'll have to wait for the page to load before you can access e.g. the title.

win.onload = function(){ alert(win.document.title); };
like image 38
livedo Avatar answered Oct 16 '22 01:10

livedo


You could use HTML5 cross-window messaging (archive.org link...but that's kind of cutting edge.

Even in that case, you'd probably need to hijack the <a> tag 'click' event with JavaScript and open the window yourself so that you'd have access to the new window object for posting messages.

like image 34
sje397 Avatar answered Oct 16 '22 00:10

sje397