/    Sign up×
Community /Pin to ProfileBookmark

How to set focus to other Browser window

Hi,

[B][U]Summary[/U][/B]
I have a new Browser Window being created to display a document. I need a way to get that new Browser Window to recieve the focus (problem is that I need to be able to do it a time which is long after its creation).

[B][U]Detail[/U][/B]
My main application allows a document to be displayed in a [B][U]new[/U][/B] Browser Window using this JavaScript function:

[CODE]function openPreviewWindow( strURL, bDisplayFullScreen )
{
if(bDisplayFullScreen)
{
var previewString;
previewString = ‘width=’ + (screen.availWidth – 10) + ‘, ‘;
previewString += ‘height=’ + (screen.availHeight – 50) + ‘, ‘;
previewString += ‘status=yes, menubar=no, scrollbars=yes, toolbar=no, resizable=yes, top=0, left=0’;
preview_window = window.open(strURL, ‘preview_window’, previewString);
}
else
{
preview_window = window.open(strURL, ‘preview_window’, ‘width=870, height=546, status=yes, menubar=yes, scrollbars=yes, toolbar=no, resizable=yes’);
}

preview_window.focus();
}[/CODE]

This all works fine.

What I need to be able to do now is somehow write some JavaScript so that when my user does something (action irrelivant to this problem) the main application window can tell the new Browser Window (created in the window.open() function call above) to come back into focus. ie get the document to appear ontop of the main application window again.

Many thanks in advance to all those who respond. ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@felgallMar 09.2007 — Just call the following line of code again.

preview_window.focus();
Copy linkTweet thisAlerts:
@ianmainauthorMar 09.2007 — Well that was what I thought but doesn't work because the "preview_window" object doesn't exist at that time - because remember this is all happening ages (an hour or so?) after the openPreviewWindow() function was originally called.

Found the answer after some experimentation:

Just call this:

[CODE]openPreviewWindow('', 1);[/CODE]

The window.open() function obviously doesn't reload the URL when its blank and it gives a value to preview_window (so that the preview_window.focus(); actually works.

Thanks
×

Success!

Help @ianmain spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...