Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Closing a firefox tab with Visual Basic (and JavaScript if needed)

Posted on 2008-06-09
5
Medium Priority
?
2,428 Views
Last Modified: 2013-12-07
Hi,

Is there a way of closing a tab in Firefox using Visual Basic?  Through VB I can open html files into Firefox, but I'm dealing with hundreds of files and I need to close each file when it's done -- programmatically.  

Can I do this through VB, or maybe a combo of VB and JavaScript?  I have to have control through VB, but if there needs to be a little JS that's okay.

Thanks!
Gene
0
Comment
Question by:ugeb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:ysfx
ID: 21744946
What method do you use to open the html files?
0
 
LVL 11

Author Comment

by:ugeb
ID: 21745538
I use

System.Diagnostics.Process.Start(filename)

Does this matter?

0
 
LVL 3

Accepted Solution

by:
NizzeK earned 2000 total points
ID: 21751413
Hi!
If you assign a handle, e.g. like winFF01=System.Diagnostics.Process.Start(filename), you can manage individual windows. I am not sure of the syntax, but this at least works with DDEInitiate("iexplore",webpage)  or Firefox dito. Moslty I use Application.FollowHyperlink "webpage" myself.

PostMessage will soon be available (Firefox 3).
http://developer.mozilla.org/en/docs/DOM:window.postMessage
This will enable sending a closure message etc to the specific window.
This is Windows standard. see http://support.microsoft.com/kb/176391/en-us
See also SendMessage
I have attached some found VB-code as an example.
Unfortunately I haven't found the right code to close a specific tab.

If you assign different title texts in the windows, you can also scan the collection of windows and close the one that matches, using System.Diagnostics.Process.GetProcessesByName("firefox") and
if currentProcess.MainWindowTitle.Equals("titleID") then currentProcess.Kill()
See more: http://forums.msdn.microsoft.com/en-US/vblanguage/thread/9dd4a526-889d-4afe-81f9-96c44a8501ff/
 


Private Declare Function EnumWindows Lib _
   "user32" (ByVal lpEnumFunc As Long, lParam _
   As Any) As Long
Private Declare Function _
   GetWindowThreadProcessId Lib "user32" (ByVal _
   hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindowLong Lib _
   "user32" Alias "GetWindowLongA" (ByVal hWnd _
   As Long, ByVal nIndex As Long) As Long
Private Declare Function PostMessage Lib _
   "user32" Alias "PostMessageA" (ByVal hWnd As _
   Long, ByVal wMsg As Long, ByVal wParam As _
   Long, lParam As Any) As Long
Private Const GWL_HWNDPARENT = (-8)
Private Const WM_CLOSE = &H10
'
' Initiate PostCloseMessage callbacks like this:
' Call EnumWindows(AddressOf PostCloseMessage, 
' ByVal ProcessID)
'
Private Function PostCloseMessage(ByVal hWnd As _
   Long, ByVal lParam As Long) As Long
   Static PID As Long
   ' Check if hWnd belongs to PID: lParam
   Call GetWindowThreadProcessId(hWnd, PID)
   If PID = lParam Then
      ' Belongs to target process, try close 
      ' message if this doesn't have an owner. VB 
      ' apps that display a msgbox from 
      ' QueryUnload will lock a 9x box up hard, 
      ' if we don't do this test!
      If GetWindowLong(hWnd, GWL_HWNDPARENT) _
         = 0 Then
         Call PostMessage(hWnd, WM_CLOSE, _
            0&, ByVal 0&)
      End If
   End If
   ' Return true to continue enumeration.
   PostCloseMessage = True
End Function

Open in new window

0
 
LVL 3

Assisted Solution

by:NizzeK
NizzeK earned 2000 total points
ID: 21751746
Here more that I hope can shed some light on the issue.
http://www.codeproject.com/KB/applications/JWinSearch.aspx
(Not VB, however, but can still give some clues)
It handles both Firefox and IE tabs.

Well, DDEinitiate works well with "iexplore", but firefox seems to be more difficult.
btw which version of VB are you using?
Some tips above are for VB.NET

Here is a VB6 page but this will probably kill all tabs in an instance at once.
http://support.microsoft.com/kb/168204
0
 
LVL 11

Author Closing Comment

by:ugeb
ID: 31465471
Still have issues, but moved on.  Thanks!
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question