Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

javascript - Focus tab or window

for a little app, I'm opening a few windows/tabs from my script. Whether the browser opens a window or a tab is of course not in my hand.

However, I hold the references to the newly created window objects and I do change their content "remotely" from another window. This all happens under the same document.domain so no xss problem.

The problem is, I cannot reliably focus those created windows/tabs. Since I'm writing a very specific app for a customer, I'm only targeting Firefox as browser. One option I have is of course just to do a remoteWindow.alert('foobar'); to get bring that window/tab up front, but that is pretty ugly isn't it.

I found this answer How to focus window/tab like alert()?

and it's said there, that Firefox has an option to allow script focus. So finally my question is, what is that option ? I searched the about:config for "tabs" and "focus" but didn't find anything related.

How to configure ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The following appears to work in IE8 and FF13:

<script type="text/javascript">
// Stupid script to force focus to an existing tab when the link is clicked.
// And yes, we do need to open it twice.
function openHelp(a) {
    var tab = window.open(a.href, a.target);
    tab.close();
    tab = window.open(a.href, a.target);
    return false;
}
</script>
<a href="help.html" target="help" onclick="return openHelp(this);">Help</a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...