1

I have done an extensive research of this problem and still can't get an answer. The following code code works fine in Chrome:

if ($window.localStorage.getItem('adminconsole') == null) {
        $window.localStorage.setItem('adminconsole', 'adminconsole');
        $window.open('admin.html', 'adminconsole');
    }
    else {
        try {
            window.open('', 'adminconsole').focus();
        }
        catch (error) {
            alert(error);
        }
    }

when I call this code after the admin.html was opened Chrome switches focus to it, but not IE. Any idea how to make it work in IE?

Thanks

Mark
  • 4,535
  • 7
  • 39
  • 76
  • 1
    did you check out this answer? http://stackoverflow.com/questions/2600186/focus-doesnt-work-in-ie – boroboris Apr 12 '17 at 10:31
  • It's not about input fields. Although, I tried timeout, did not work for me. Is it working for you? – Mark Apr 12 '17 at 10:32
  • no I haven't tested it just seemed like it will work. :) I've found this too: http://stackoverflow.com/a/5651750/5142901 . maybe you should try different approach and focus the window you just opened from inside that window – boroboris Apr 12 '17 at 10:40
  • In your else case, do you want to focus an existing tab that has already been opened? Because right now you are opening a new tab. – Ozan Apr 12 '17 at 10:44
  • I want to switch to existing tab. The code works fine in Chrome. – Mark Apr 12 '17 at 10:46
  • @boroboris. How exactly do I send a signal to existing tab to obtain the focus? – Mark Apr 12 '17 at 10:47
  • @Mark, you use `focus()`. You are doing it right, but microsoft is preventing you access to the other tab for security reasons. If you check your console, you should be receiving *Acess denied* errors. – Ozan Apr 12 '17 at 10:52
  • Nope, dont see any errors. Clearly a bug. – Mark Apr 12 '17 at 15:56
  • @boroboris. "maybe you should try different approach and focus the window you just opened from inside that window". I am trying it. How do I set a focus from the inside? Just window.focus()? Doesn't look like it works.\ – Mark Apr 12 '17 at 15:58
  • sorry I couldn't answer earlier. not quite the solution you're looking for but it could help. btw which IE version do you test this on? – boroboris Apr 12 '17 at 17:40

1 Answers1

0

So from what I've found you can't focus tab in the IE. What you can do however is open a popup and focus it. I've been able to test it on Microsoft Edge, I don't have other browsers currently.

main.html

<script>
        function openPopup() {
            window.open("[path_to_file]/admin.html", null, "height=200, width=200");
        }
</script>
<button onclick="openPopup()">Open popup</button>

admin.html

<script type="text/javascript">
  function focusMe() {
     //alert('focusing');
        window.focus();
    }

 (function () {
     setTimeout(function() {
      focusMe();
     }, 5000);
 })();
</script>

<h1>admin</h1>

I hope this helps.

boroboris
  • 1,548
  • 1
  • 19
  • 32
  • I've edited answer a bit. have you tried window.open("[path_to_file]/admin.html", null); and than the code from admin.html to try to focus it that way? – boroboris Apr 12 '17 at 17:50
  • Assuming I am doing it correctly all I get is a popup on a top of the first tab. It doesn't switch to the second one although code that creates the popup actually executes in the second tab. – Mark Apr 12 '17 at 17:54
  • in my case popup opens (in a new window), and if I move it from focus it focuses after the 5 seconds have passed. the comment was to try just in case. – boroboris Apr 12 '17 at 18:11