/    Sign up×
Community /Pin to ProfileBookmark

placing focus on link in popup

On my site when a developer clicks on the start button to start his time, call a popup that handles the backend stuff then has a link that they click to close the window that refreshes the parent page so it now shows the stop time button.

How can I place focus on this link when that popup comes up so that they can just hit enter to close it? It will save the step of mousing over and clicking.

Here’s the code I call for refresh:

<script>

function refresh()
{
opener.location.reload()
window.close()
}

</script>

$value .= “Your time has Started. <p>

<a href=”javascript:refresh()”>Click Here to Close</a> (Please use link to close window)”;

Thank you for any help.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@Phil_KarrasAug 01.2003 — Have you tried things like:

window.focus();

or

document.formName.FieldName.focus();

?
Copy linkTweet thisAlerts:
@tripwaterauthorAug 01.2003 — yes.


I tried :

<script>

document.linkname.focus()

</script>

<a href=refresh() name=linkname>click me</a>

and these in the script tag :

document.links[0].focus

window.focus();

none of these seem to work.
Copy linkTweet thisAlerts:
@Phil_KarrasAug 01.2003 — Since I see no code for the opening of the pop-up I can't really say, but I have always been able to put the focus where I want it, either the popup or the parent whenever I want to, so I know your case can probably be done.

Here are some of the things you may need to do:

[color=blue][b]In the popup if you want focus to be there:[/b][/color]

- normally it gets the focus at the start, you have to specifically remove it's focus in the parent.

  • - You can put code in the popup to keep the focus such as: [b]document.focus();, window.focus();...[/b]


  • - You can put code in the window.opener (the parent) to put the focus on the popup such as: [b]NewWin.focus(); ...[/b]


  • [color=blue][b]If it is the other way round, you want focus to remain in the parent (window.opener) then you do the opposite, use:[/b][/color]

    - in the popup: window.blur();

    - or in the parent: NewWin.blur(); then window.focus();

    Try from both ends till you find what works, then remove things till it breaks so you can get to the minimum needed to make it work.

    Good-luck.
    Copy linkTweet thisAlerts:
    @tripwaterauthorAug 01.2003 — My popup has focus...I need the link inside it to have the focus so the user can hit enter instead of clicking it.
    Copy linkTweet thisAlerts:
    @Phil_KarrasAug 01.2003 — OK, that clarifies the problem! I really did not understand that from all your previous postings.

    First I will say that I have only ever seen the "Enter-Key" work on the [submit]-button, but if we can get the focus to the link it might just work.

    If the link is HTML then you'll need to give it a name like:
    <i>
    </i>&lt;a href='MyImage.jpg' id='MyImage'&gt;
    &lt;img src='MyImgaeThumb.jpg'&gt;
    &lt;/a&gt;


    Now perhaps you can get focus there by using:
    <i>
    </i>function Here() {
    var obj=document.getElementById(MyImage';
    obj.focus();
    }

    &lt;!-- and now --&gt;
    &lt;body onLoad='Here();'&gt;


    I have [b]NOT[/b] tried this, but if we can get the focus to the object (or on the image itself in this case) it should work. Give it a try & let us know.
    Copy linkTweet thisAlerts:
    @tripwaterauthorAug 01.2003 — That did it thanks!

    another question....I have this being called when you click the link (or hitting enter now) to refresh the parent page to show the new button.


    function refresh()

    {

    opener.location.reload()

    window.close()

    }


    <a href="javascript:refresh()" id="focus">Click Here to Close</a> (Please use link to close window)


    THis works fine in mozilla/Netscape but for some reason does not seem to reload my page in IE. Once I manually hit the refresh it shows me what I want to see and all of my backend code is successfully kicked off. But to the user in IE it looks like it did not work.

    Any thoughts?
    Copy linkTweet thisAlerts:
    @Phil_KarrasAug 01.2003 — Glad to hear it! ?

    For your next question... I think I'd do it the other way round.

    It looks to me like you're refreshing the parent, then closing the popup in the popup.

    There's no reason this should not work in IE that I know of, however, you might be able to get around it by coding a bit differently.

    Try a time delay before closing the popup, OR

    have it call a function in the window.opener to do this & change the order?

    In the POPUP:
    <i>
    </i>function refresh() {
    window.opener.Refresh() ;
    }



    In the window.opener:
    <i>
    </i>function Refresh() {
    PopUpWin.close();
    document.location.reload();
    }



    Of course, the problem may simply be your non-standard way of accessing things, remember to ALWAYS use [color=blue]window.opener[/color], not [color=red]opener[/color], [color=blue]document.location[/color], not [color=red]location[/color] etc.

    Usually it's NS that's more picky about those things, but ya never know.
    Copy linkTweet thisAlerts:
    @tripwaterauthorAug 01.2003 — Well that did not work...thank you for your time I have to move on to another project. Thanks again for your help on the focus() prob.
    ×

    Success!

    Help @tripwater 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.17,
    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: @nearjob,
    tipped: article
    amount: 1000 SATS,

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

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