/    Sign up×
Community /Pin to ProfileBookmark

Shift focus to a new window

Hi. I have a page which spawns another (popup) which shows an autogenerated password. The new window is called Password.

I want to put a link on the parent page which will shift focus to the Password window when clicked, so the punter doesn’t think the password window has closed if it just loses focus to the main page. (IYSWIM)

I’ve tried <a href=javascript?assword.focus()> and <a href=javascript:window.Password.focus()> and almost every other combination I can think of but they all show an error.

Any help, anybody?

Thanks a bunch

===Toby===

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@AdamBrillMar 13.2003 — This will make it blink on the task bar:

<a href="javascript:win.focus()">focus</a>

Notice the quotes... But, I think this would be closer to what you really want. This should go in the head:

win = null;

function focusme(){

if(win){

win.close();

}

win = window.open();

}

And this is the link:

<a href="wherever.htm" target="blank" onclick="focusme(); return false;">focusme</a>

I hope that helps... ?
Copy linkTweet thisAlerts:
@tobywallisauthorMar 13.2003 — Thanks, Adam, but I think not quite...

The window that changes the focus is the *parent* window, not the child. So it must identify the window of the child (by name, presumably) and the routine wouldn't be "focus me" but "focus Password" ... or something?

Thanks

===Toby===
Copy linkTweet thisAlerts:
@JonaMar 13.2003 — <html><head>

<script>

function focusPwd(){

var pwd = window.open("file.html","pwd");

if(window.blur()){ pwd.focus(); }

}

</script>

</head><body>

<a href="javascript:focusPwd()">Open</a>

</body></html>

That should work.
Copy linkTweet thisAlerts:
@tobywallisauthorMar 13.2003 — Thanks, Jona. But I don't want to *open* the window on the link; it already exists. All I want to do is change focus to it.

Or am I missing something?

===Toby===
Copy linkTweet thisAlerts:
@JonaMar 13.2003 — Ok. But the window has to have a name. So how is the window opened? If you're using target="_blank" in the <A> tag, then change it to, target="windowName" And then use this:

<html><head>

<script>

function focusPwd(){ if(window.blur()){ pwd.focus(); } }

</script>

</head><body onload="focusPwd()">

</body></html>

That should do it.
Copy linkTweet thisAlerts:
@tobywallisauthorMar 14.2003 — Dear Jona,

The new window is opened onLoad using the following:

<body onload="window.open('http://window.URL','Password','top=400,left=10,width=450,height=250,resizable')"> (so I *think* the window is called Password, but is the window title the same as Target=? If not maybe I should add a Target= into the above)

Then later I try to shift focus to it using

<a href="javascript?assword.focus()">Click here to bring password window to the front</a>

Does that hlp?

Thanks!

===Toby===
Copy linkTweet thisAlerts:
@tobywallisauthorMar 14.2003 — Hi Jona,

I did it - changed the way the popup window is opened & wrote 2 functions:

<head>

<script>

var fs = null;

function PasswordScreen(url)

{

fs = window.open(url,'Password','top=400,left=10,width=450,height=250,resizable');

fs.focus();

return true;

}

function focusPasswordScreen()

{

if(fs != null && fs.open && fs.focus)

fs.focus();

}

</script>

</HEAD>

<body onload="PasswordScreen('http://window.URL')">

<a href="javascript:this.focusPasswordScreen()"><i>Click here to show Password Window</i></a></p>

</body>

Thanks for all your help

===Toby===
Copy linkTweet thisAlerts:
@JonaMar 14.2003 — Yah, it's no problem. About the target= though. Target=windowName but the only problem with that is it have to be either a global variable or only inside the function. Otherwise windowName = undefined.
Copy linkTweet thisAlerts:
@tobywallisauthorMar 15.2003 — Thanks I'll remember that...

Over and out
×

Success!

Help @tobywallis 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...