Is it possible to switch focus to windows or tabs based on user input using javascript or any other technology?

  • I have a webpage that shows a list of results.

  • I click on one of the results to view the product. It opens a new window / tab.

  • Now I have 2 windows / tabs from the same website, but 1 shows the results page and the other product page.

  • Inside the product page, I have a link that says "Back to the list"

  • If I click on it, I will return to the same list of results.

  • So now I have two windows / tabs showing the same list of results.

New behavior that I'm interested in knowing if it works:

a) if I click "Back to the list" on the product page, can I switch the focus to the initial window / tab, which displays a list of results, and not what I described in 5 and 6?

b) if the answer to the question is yes, can I do for several product windows? those. if i repeat step 2 several times?

+3
source share
1 answer

You can do something like this:

var BackToList = function() {
    window.opener.focus(); // this sets the focus on the window that opened your product
    window.close();  // and this closes the product window
};

Then your link should call the function BackToList.

If your link is a simple tag aAND has an identifier, you will look like this in your loadevent window :

document.getElementById("the id goes here").onclick = BackToList;
+3
source

All Articles