DonCroce
DonCroce

Reputation: 475

Bring window to front

How can I bring a non-active (means another window is in front of that page) to the front? I've tried self.focus and window.focus, but it doesn't work...

I can't control the window in the front, because it's from a third-party plugin...

many thanks to every hint :)

Greetz, Camillo

EDIT: Here the code I'm using on my site (that i'm trying to bring to front):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gallery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
   var timeFrame;
   $(function() { timeFrame=setInterval("lpcAuto();", 100);});
   function lpcAuto(){
     if ( $(document.activeElement).attr('id')=="lpcframe" ){

// HERE THE SNIPPET I'M SEARCHING :)

}
   }
</script>

Upvotes: 1

Views: 6273

Answers (2)

ecc
ecc

Reputation: 1500

I performed the following test in Firefox 45 and wanted to share:

setTimeout(function(){window.focus()}, 2000);

a) Alt-tab to another window will bring the desired window to the front after 2s.

b) Minimizing the window will restore it and bring it to front after 2s.

c) Changing tabs will not let the tab re-gain focus.

d) Changing tabs and then Alt-tab to another window will not bring the first window to the front.

Upvotes: 1

Gaurav
Gaurav

Reputation: 12796

First, you have to call blur() on the window that is on top. Then call focus() on the window that you want to call to the top.

Also note that browsers these days have popup blockers that prevent you from doing this, and you must disable these.

Upvotes: 2

Related Questions