Link to home
Start Free TrialLog in
Avatar of Aryabhatta M
Aryabhatta M

asked on

How to refresh only a particular tab in DEFAULT browser, other tabs should not refresh

My default browser is launched when a batch calls this VB Script and refreshes as the application does not open instantly and needs refresh. But it is refreshing all the tabs. I want the particular tab to get refreshed with this particular URL and once the application is  open the refresh operation should stop. can it be done within this VB script.

My code:  

Option Explicit
      
      Dim myowmObj
      Dim ObservedPort
      Dim Counter
 
    Set myowmObj=WScript.CreateObject("WScript.Shell")
    ObservedPort = WScript.Arguments(0)
    myowmObj.Run "http://localhost:"&port&"/HatsDemo"
      'Wait for 3 seconds
      Wscript.Sleep 3000
     
      Counter = 20
      Do While Counter > 0
            Counter = Counter - 1
           
            'Send the F5 key for a refresh
            myowmObj.SendKeys "{F5}"
            'Wait for 2 seconds
            Wscript.Sleep 2000
      Loop
Avatar of Qlemo
Qlemo
Flag of Germany image

As I said in your other question, https://www.experts-exchange.com/questions/29072404/In-a-Batch-script-how-to-refresh-webpage-after-launching-in-default-browser.html, it is very unreliable to use SendKeys, in particular for repeated key strokes and delays.

Whatsoever, F5 in all browsers I know just refreshes the current tab.

The next request is not feasible with your approach at all. You just spawn a new browser tab, and do not have any relation to it in VBS after doing so. Hence you have nought control over it.
You can use indirect measures, like checking windows titles for something specific only appearing if the "application is open" (whatever that means). But again, since indirect and depends on the browser's behaviour about setting windows titles, it is unreliable.

The way I showed in the other question puts some restrictions in (it forces use of IE), but that is the only way to get enough control over a browser.
Avatar of Aryabhatta M
Aryabhatta M

ASKER

While the iterative refresh goes on if you click another tab and open in monitor it will refresh that page too. If desktop is open it will refresh desktop :-)
As I mentioned, that is the price to pay for the indirect approach. You would have to write your own JavaScript code doing the start + refresh + checks etc, and run that instead of your URL. Or use what I have shown in the other question, using a IE object.
With your current approach, the only improvement you can try is to explicitly activate the window you want to address. That works if there is unique windows title. You just run
myowmObj.AppActivate title

Open in new window

immediately before using SendKeys, where title identifies the head part of the window title. If non-unique, the first found will be activated, so make sure to be as specific as possible.
Can I atleast stop the refresh once it loads the page ?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I added AppActicvate before Run statement. But same effect. Seems not possible to do.
You need to place it before  myowmObj.SendKeys "{F5}". Having it before Run won't have any effect, of course.