Access other top window by name

  • Thread starter simon.niederberger
  • Start date
S

simon.niederberger

Hi all

I'm developing a web-app for IE (7, 8) which has following reporting
feature:

The main window of the application contains a menu and some other
buttons, plus an IFRAME hosting the current application page. The main
window is 'load once'. Reports open in a new 'top' window (i.e. new
tab or new window, depending on the user's IE settings). Reports may
contain links. If the user clicks on a link, it should open in the
IFRAME of the main window.

top1: main window -> IFRAME
top2: report window with Links

Setting a 'target' on the links to the IFRAMEs name (or that of
iframe.contentWindow) doesn't work. It seems to me that the report
window is simply not aware of the IFRAME in the other window. As both
windows originate from the same domain, I guess cross-site scripting
shouldn't be an issue and somehow I should be able to get hold of the
other window. If yes, I could set the src there with Javascript.

report window: a href="#" onclick="loadLinkInIframe('targeturl.html')"

function loadLinkInIframe(targeturl) {
var topwnd = WHAT GOES HERE?
var ifrm = topwnd.frames['bodyframe'];
ifrm.src = targeturl;
}

Thanks
Simon
 
B

Bart Van der Donck

I'm developing a web-app for IE (7, 8) which has following reporting
feature:

The main window of the application contains a menu and some other
buttons, plus an IFRAME hosting the current application page. The main
window is 'load once'. Reports open in a new 'top' window (i.e. new
tab or new window, depending on the user's IE settings). Reports may
contain links. If the user clicks on a link, it should open in the
IFRAME of the main window.

top1: main window -> IFRAME
top2: report window with Links

Setting a 'target' on the links to the IFRAMEs name (or that of
iframe.contentWindow) doesn't work. It seems to me that the report
window is simply not aware of the IFRAME in the other window. As both
windows originate from the same domain, I guess cross-site scripting
shouldn't be an issue and somehow I should be able to get hold of the
other window. If yes, I could set the src there with Javascript.

report window: a href="#" onclick="loadLinkInIframe('targeturl.html')"

function loadLinkInIframe(targeturl) {
  var topwnd = WHAT GOES HERE?
  var ifrm = topwnd.frames['bodyframe'];
  ifrm.src = targeturl;
}

I'm not sure if your design is optimal, but 'window.opener()' should
normally refer to the page that opened the current window.

https://developer.mozilla.org/en/window.opener (Mozilla)
http://msdn.microsoft.com/en-us/library/ms534309(VS.85).aspx (MSIE)
http://www.google.com/search?q=window+opener

IIRC there might be some compatibility issues.
 
S

Simon

Hi Bart

Thanks for the reference. Apparently the window.opener is something to
be used with window.open() and only works for frames (frame, iframe).
In my case a form post will have a target='_blank', so that new window
will know nothing of it's originator. The new window does however have
the window name, so if there is a window collection or something
(ideally: navigator.getWindowByName()), I could get a reference to
that window object and continue from there.
 
S

Simon

Hi Bart

I take everything back, your a hero. window.opener is in fact set for
a window created by a

<form target='_blank'>

and points directly to the contentWindow of the IFRAME is was looking
for. So now it's just

window.opener.location = mytargeturl;

Thanks a bunch
Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top