Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a window by window name

Tags:

javascript

If I open a window using

window.open('myurl.html', 'windowname', 'width=100,height=100'); 

How do I refer to the new window (from the same page that opened it) using 'windowname'? This question is specifically about this. I'm aware that I could save a reference to the handle by using "var mywin = window.open(...)" but I don't care about that in this situation.

Thanks, - Dave

like image 534
Dave Avatar asked Aug 30 '11 13:08

Dave


People also ask

When a window is open the name of the window is displayed on the?

The title bar is a horizontal bar located at the top of a window in a GUI. It displays the title of the software, name of the current document or file, or other text identifying the contents of that window.

What is window name?

The window title for a page (often called the "title tag") is, most simply, the text that appears at the top of a visitor's web browser when viewing that page. (The same text also appears in the title bar of Sandvox when working on a site document, preceded by the icon and name of the Sandvox document itself.)

How do I get the URL for a popup window?

Open UiExplorer, and get the selector of that popup. Use an On Element Appear activity, put in the selector of that popup. in the On element Appear activity, place a Get Attribute activity, “url” to get the url of the popup.

What is window opener?

opener. The Window interface's opener property returns a reference to the window that opened the window, either with open() , or by navigating a link with a target attribute. In other words, if window A opens window B , B. opener returns A .


2 Answers

If you didn't save a reference to the window then there is no way to restore it. However, if that window is still open and if the page loaded there belongs to the same domain as your page, you can run JavaScript code in it:

window.open("javascript:doSomething()", "windowname"); 

Whether that's sufficient in your scenario depends on what you are trying to achieve.

like image 153
Wladimir Palant Avatar answered Sep 29 '22 06:09

Wladimir Palant


In firefox (might work in other browsers too, but now it's not my concern) I was able to reference one window accross multiple page loads with

var w = window.open("", "nameofwindow"); 

This opens new window if it doesn't exist and return reference to existing window if it does exist without changing contents of the window.

With jQuery I was then able to append new content, to make quick collection of interresting links like this

$('body', w.document).append(link_tag); 
like image 30
Petr ''Bubák'' Šedivý Avatar answered Sep 29 '22 07:09

Petr ''Bubák'' Šedivý