views:

64

answers:

4

Hi,

I am using mozilla firefox and am trying to figure out a way to access the content of other tabs in the same window with the help of javascript and DOM (am open to other techniques if exist). Would someone help me?


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 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.

I'm sorry if it sounds confusing.

Thanks,
Vamyip

+1  A: 

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.

sje397
A: 

is this link what you're talking about?

OddCore
I don't really think you understood the question...
Vincent
+4  A: 

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.

Paul Hadfield
yes..I know that. But, as I mentioned earlier, the new tab/window will belong to the same domain, so I won't possibly "steal" bank account details from my own website. Anyways thanks for your prompt reply guys...but need to find a workaround for this. - Thanks again
vamyip
A: 

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