Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preventing a browser from losing focus on external app call

I'm building a quick VOIP demo using Skype and when I press a call button, the Skype application takes the focus away from the browser. You can try here http://developer.skype.com/skype-uris/skype-uri-tutorial-webpages where you'll find several "Try it here" links. When I click those links, I would like the browser to maintain focus. Is there a way to do this?

Thanks.

like image 834
frenchie Avatar asked Sep 30 '13 19:09

frenchie


3 Answers

What you would need to do is apparently called "focus stealing" from my web searches.

At least as far as Windows is concerned, there does not seem to be a reliable way to do this from the browser alone.

I just googled "focus stealing" (which is what the JavaScript only solution would need to do to get this done) and found many answers showing that, though theoretically possible, depending on the configuration of Windows stealing the focus away from Skype by the browser would probably not work in the majority of cases.

The complaints in the Google links are numerous and some answers conflict, but it looks like reliably "stealing the focus" back to the browser is not going to be supported.

This is a good thing though, if you think about it - I do not personally want just any old JavaScript program running in my browser to change my focus from what I am working on back to the browser willy nilly - this would be a very annoying behavior for a web page to be able to do at best, making my system useless at worst.

If you could do it in this case using some methodology allowed in a browser, so could anyone else - even malevolent websites.

The best answer is to never let the focus leave the browser, but I have no idea how to do that in your specific case. Perhaps whatever means you are using to launch Skype may have an option or something to launch it in the background or whatever, never changing the focus.

I did not hit on specific links pertaining to Apple OSes, Linux or mobile OSes, but I have a feeling the same concerns and limitations apply for those as well.

Here are some of the links on the Google search (and sorry about the bad news for your needs):

Microsoft Answers Forum Post

Focus stealing is evil

http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm

like image 193
Xitalogy Avatar answered Oct 20 '22 07:10

Xitalogy


you can open it on new window, then close the new window and refocus on yours

somthing like:

a=window.open('skype:ohadcn?chat',10,10);
//i couldn't find a relevant event, onload() do not work for me here
//so i used setTimeOut, hoping that two seconds is enough to open skype but not enough to loose the user
setTimeout(function(){ a.close();window.focus();},2000)
like image 21
Ohad Cohen Avatar answered Oct 20 '22 06:10

Ohad Cohen


I went to the skype tutorial page in Chrome, brought up the console and tried Ohad's answer, but it would not return the focus to the tutorial web page.

I even tried a script to perpetually put the focus in the Search textbox:

    function ASDF() {
      document.getElementsByName("q")[0].focus();
      setTimeout(ASDF, 1000);
    } 
    setTimeout(ASDF, 1000);

Still no luck.

I tried changing Ohad's script so that it would reopen the tutorial page in a new window after the skype app opened. It would work if the tutoral/console page was the only tab in the window:

a=window.open('skype:ohadcn?chat',10,10);
setTimeout(function(){ 
  a.close();
  a=window.open('http://developer.skype.com/skype-uris/skype-uri-tutorial-webpages', 10, 10);
  window.close();},2000);

However, if the tutorial page/console script was in window with other tabs, it did not return focus to the reopened page. Not to mention, IE might warn the user that the original page is trying to close.

I do not think there is a way to consistently achieve your goal, but I reserve the right to be wrong.

like image 42
jaybro Avatar answered Oct 20 '22 07:10

jaybro