Question

We are opening a webpage when a user clicks a button from an external program (non-web). The problem is, when the user goes back to the program and opens another one, it opens in the same browser window but a different tab. After a few hours of this, our non-tech savvy clients have 30+ tabs open which really slows down their computer.

The language we are using in the external program is RPG (IBM iSeries). We haven't found a way to target the same tab from RPG. The user is sitting at a specialized telnet session called 5250 where the server program (RPG) can call exe's on the connected PC. It can also call URL's and that will use the client's default web browser. When doing this the only real parameter you can specify is the URL itself, so we're thinking the solution needs to be entirely in the browser. We could write an exe to call the browser, but that would defeat the purpose of migrating these to web apps.

Is there a way to achieve this with HTML/JavaScript/PHP/etc? We have tried having the external program call a redirect script (JavaScript) that will target a browser tab and then close itself. This would be a great solution if browsers weren't so picky with security.

Firefox: has a special setting you have to set so JavaScript can close the tab IE: won't open the popup until the user picks 'allow popups from this domain'. but the original tab closes itself before the user gets to do this. Chrome: Chrome kills the reference to the named tab. So, each new popup opens in a new tab anyway (even though they are calling the same target name).

We have been getting really creative with this but haven't come up with a solid solution. This is an intranet project, but we'd like to avoid having to install or set things on each computer due to the sheer number of PCs at these companies.

In a nutshell, the main issue is the second RPG opens a new window, that new window doesn't have any reference to previously opened named tabs.

Was it helpful?

Solution

I'm a bit thinking out of the box here mainly because I have no idea how your programs work. To start of, there is literally no way to close a X-tab, where x is the tab you want. The only way is to actually be in that tab/page to close it. That's with PHP, HTML, JS etc. I assume you can achieve it with some C++/C# or whatever runs on your "client" rather than browser.

Now, the out of the box possible solution is to have some session management and an ajax call. My suggestion is to create a new session on a new tab. User gets a new tab, you give it number 1. Every x-seconds you do a ajax call to a script, which simply checks what "tab" it is. Let me give an example.

User opens a new tab, session is started and you have an array with the following:

$_SESSION['tabs'][1] = 'set';

Now this tab keeps doing calls to a file, to see if it should stay "alive". Basically you post with "Hi, I'm tab 1". When you check the session, tab 1 should be the only 1 there.

On a new tab, the session tabs gets an other value, named "2" which gets set. Now when tab 1 posts to the ajax caller, it should give a message back that it can be closed. When it receives that message it should invoke some JS like:

javascript:window.open('','_self').close();

This is just thinking out loud, I guess the basic idea should work, tho I have never tested it nor can I give you a full code example. Perhaps when I got some spare time I could try to create this.

OTHER TIPS

If you name a frame in target that doesn't exist, it will open up in a new tab. Use the same frame name, it will continue to use that tab.

Have you considered creating a quick Handoff application that is called from the RPG rogram to handle the browser request? This will allow you to specify that the same tab should be used when a new request is made as well as sending specific parameters for customization. See this response from Karl Anderson ==> Reusing browser/tab in VB.net

similar code below:

Private Sub ToUrl(ByVal url As String, ByVal strDocType As String, ByVal strSSN As String)
        Dim IE As SHDocVw.InternetExplorer
        IE = GetTopmostInstanceOfCustomApp() ' Get the topmost instance of custom app (will return new instance if not running)
        If Not IE Is Nothing Then
            Dim Header As String = "Content-Type: application/x-www-form-urlencoded" & Chr(10) & Chr(13)
            SetForegroundWindow(IE.HWND)
            url = url & strCustomParameter
            IE.Navigate2(url, , , , Header)
        End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top