Accessing the content of other tabs in 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 DOM (I am open to other techniques if exist).

E.g. I want to run a JavaScript 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 hyper link 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.

Answers:

Answer

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.

Answer

Vamyip,

Try setting a cookie which is accessible to any page in the same domain. On other pages, use a javascript timer to check if the cookie value has changed and when it has you can use its value and take an action.

It worked for me.

Answer

You could use HTML5 cross-window messaging...but that's kinda cutting edge.

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

Answer

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); };

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.