Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Pop-up blocker parsed in VB script? Can this be scripted?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,41470
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Pop-up blocker parsed in VB script? Can this be scripted?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Pop-up blocker parsed in VB script? Can this be scripted? - 12/27/2006 8:20:24 AM   
  AngieX

 

Posts: 6
Score: 0
Joined: 12/27/2006
Status: offline
Hi, I am hoping someone can help me craft a simple VB script as a sub-function I need, which can stop IE pop-ups before they appear so there is no flicker? Can this be done? I am conducting some experiments and building a app which will have this feature. :)  Thank you! Happy Holidays & New year! -AngieX
 
 
Post #: 1
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/27/2006 4:48:36 PM   
  TNO


Posts: 1397
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: online
Flicker? I think thats an issue with your computer's performace, not IE. I've never seen any flicker when a pop-up is being blocked. (I'm currently using Windows XP pro with a pentium 3 and 128 mb of RAM, and I don't see any flicker)

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to AngieX)
 
 
Post #: 2
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/28/2006 4:14:43 AM   
  AngieX

 

Posts: 6
Score: 0
Joined: 12/27/2006
Status: offline
I am sorry, what I meant by Flicker is the brief appearance of the offending IE pop-up briefly before it is removed.  Some pop-up blockers achieve their result by stopping pop-ups before they appear and some after they appear, which I hope to do something about in my situation :))

(in reply to TNO)
 
 
Post #: 3
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/29/2006 10:57:22 PM   
  TNO


Posts: 1397
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: online
Well, the short answer is no.

The longer answer is yes, its possible but is pretty lengthy and complex and not guaranteed to work. My only theory to how it could be used is by using vbscript to obtain the source code of the website in question, parse it, and remove any window.open methods or target="_blank" attributes..this will slow your browsing time by ALOT. I suggest you upgrade to IE7 or use firefox if it bothers you alot. You could also install Google's popup blocker as an alternative. Besides it'll save you some work.

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to AngieX)
 
 
Post #: 4
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/30/2006 4:20:34 AM   
  AngieX

 

Posts: 6
Score: 0
Joined: 12/27/2006
Status: offline
Someone posted this code on Usenet and trying to figure out if this is bogus or could work.  I am still not VB expert and don't know if this is rouge code or leght   Can you see if this indeed would solve my problems and could be modified to be a universal pop-up blocker?  It appears to want to look for something specific but not sure.  What is going on in there?  Thanks so much for your thoughts, assistance if you can!    DOUBLE !!!!!

Happy New Years!




'1

'Known bug : don't do right click on an IE icon in the taskbar, it freezes
Set J=CreateObject("Shell.Application")
on error resume next
Do
WScript.Sleep 2000
if instr(ucase(wscript.fullname),"CSCRIPT") Then wscript.echo Now
For L=0 to J.windows.count-1
With J.windows.item(L)
If IsObject(.document.frames) Then
If Not isObject(.document.frames.opener) Then
Else
.document.frames.close
End if
End If
End With
Next
Loop

' 2

Dim gstrDataFile 'As String -- Name of text file containing bad window titles
Dim strEngine 'As String -- Used to tell the user what program is running the wscript.
gstrDataFile = FileNameLikeMine("txt")
If Not CreateObject("Scripting.FileSystemObject").FileExists(gstrDataFile) Then
    String2File "----- Title Data File -----" & vbCrLf & "www.quellochevuoi" & vbCrLf & "about:blank" & vbCrLf,
gstrDataFile
    strEngine = Wscript.FullName
    strEngine = Mid(strEngine, InstRrev(strEngine, "\") + 1)
    strEngine = Left(strEngine, Instr(strEngine, ".") - 1)
    strEngine = Ucase(Left(strEngine, 1)) & Lcase(Mid(strEngine, 2))
    MsgBox "    This script will run until system shutdown killing windows whose titles are found in the ""Title Data
File"" at """ & gstrDataFile & """." & vbCrLf & vbCrLf & "    If you need to stop this process, kill the """ &
strEngine & """ program with the Windows Task Manager (Ctrl-Alt-Del). Alternatively, you can stop the program by
deleting, renaming, or emptying the title data file." & vbCrLf & vbCrLf &  "    This dialog will only appear when there
is no title data file."
End If
While True
    KillWindows
    Wscript.Sleep 500
Wend

Sub KillWindows
Dim wsh 'As WScript.Shell
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Dim strData 'As String -- Entire contents of gstrDataFile
Dim strTitle 'As String -- Just one bad window title
Const ForReading = 1
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set wsh = CreateObject("WScript.Shell")
    On Error Resume Next
    Err.Clear
    Set ts = fs.OpenTextFile(gstrDataFile, ForReading, True)
    If Err.Number = 0 Then
        strData = ts.ReadAll
        If Err.Number = 0 Then
            'Read all title lines in data string
            Do Until (Instr(strData, vbCrLf) = 0)
                strTitle = Left(strData, Instr(strData, vbCrLf) - 1)
                strData = Mid(strData, Instr(strData, vbCrLf) + 2)
                If strTitle <> "" Then
                    If wsh.AppActivate(strTitle) Then
                        wsh.SendKeys "%{F4}"
                        WriteLog Now & " " & strTitle
                    End If
                End If
            Loop
            'Grab last bit in case there was no ending CrLf
            strTitle = strData
            If strTitle <> "" Then
                If wsh.AppActivate(strTitle) Then
                    wsh.SendKeys "%{F4}"
                    WriteLog Now & " " & strTitle
                End If
            End If
        Else
            ts.Close
            Wscript.Quit 1
        End If
    Else
        Wscript.Quit 1
    End If
    ts.Close
End Sub

Sub WriteLog(strText)
'Write to screen if script is run with CSCRIPT. Otherwise, write to a log file.
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Const ForAppending = 8
    If Lcase(Right(Wscript.FullName, 11)) = "cscript.exe" Then
        Wscript.Echo strText
    Else
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log",
ForAppending, True)
        ts.WriteLine strText
        ts.Close
    End If
End Sub

Function FileNameLikeMine(strFileExtension) 'As String
'Returns a file name the same as the script name except
'for the file extension.
Dim fs 'As Object
Dim strExtension 'As String
    Set fs = CreateObject("Scripting.FileSystemObject")
    strExtension = strFileExtension
    If Len(strExtension) < 1 Then strExtension = "txt"
    If strExtension = "." Then strExtension = "txt"
    If Left(strExtension,1) = "." Then strExtension = Mid(strExtension, 2)
    FileNameLikeMine = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & strExtension
End Function

Sub String2File(strData, strFileName)
'Writes a string to a file
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Const ForWriting = 2
    Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(strFileName, ForWriting, True)
    ts.Write(strData)
    ts.Close
End Sub

< Message edited by AngieX -- 12/30/2006 5:16:26 AM >

(in reply to TNO)
 
 
Post #: 5
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/30/2006 5:23:06 AM   
  dm_4ever


Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
The second example seems to be reading a text file with window titles.  The script then looks at any open windows that have a title matching any in the text file and closing the window with any of those titles.  I'm not too sure about the first example.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to AngieX)
 
 
Post #: 6
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/30/2006 5:56:18 AM   
  AngieX

 

Posts: 6
Score: 0
Joined: 12/27/2006
Status: offline
quote:

ORIGINAL: dm_4ever

The second example seems to be reading a text file with window titles.  The script then looks at any open windows that have a title matching any in the text file and closing the window with any of those titles.  I'm not too sure about the first example.


Could this be easily tweaked to encompass any new windows that might be opened?  I guess I am asking, can you tweak this to do that?

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/30/2006 6:42:01 AM   
  TNO


Posts: 1397
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: online
This script will result in some real slow performance. It will also do make a "flicker" worse than the normal pop-up blocker. (only checks twice a second). Since it uses SendKeys to send Alt+F4, there is a good chance that it could miss and close windows you wouldn't want closed (like the browser itself). There is a significant number of websites that use PopUnder windows to get around stuff similar to this very thing. Its seriously best to use the inherent popup blockers already available in the browser. (Or the add-on toolbars from google or yahoo). Imagine if you were trying to use or create a website that requires the use of a popup, it would close almost immediately everytime you opened it. This is honestly in my opinion a very dirty script and I wouldn;t suggest anyone use it as a replacement for the already existing technologies for this problem; VBScript cannot compete in this regard. The ONLY way I would suggest a hand-made pop-up blocker is if you embedded an instance of the internet explorer object inside another application as an activeX control (Which is highly unnecessary I believe in the first place in comparison to alternatives)

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to AngieX)
 
 
Post #: 8
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/31/2006 5:31:04 AM   
  AngieX

 

Posts: 6
Score: 0
Joined: 12/27/2006
Status: offline
TNO -- here is a very interesting thread I found:

http://groups.google.com/group/microsoft.public.inetexplorer.scripting/browse_thread/thread/a323819e1dc509ff/042352188d1f608e?lnk=st&q=.document.frames.close&rnum=1&hl=en#042352188d1f608e

option explicit
dim shApp, x, bTest
set shApp=createobject("shell.application")

For x=0 to shApp.windows.count-1
With shApp.windows.item(x)
  on error resume next
  bTest = IsObject(.document)
  if err<>0 then bTest = false
  on error goto 0
  If bTest Then

  'This should close the google search page
  If .LocationName = "Google" Then
    .document.parentWindow.opener = "me"
    .document.frames.close
  End If

End If
End With
Next

This above code is supposed to close single pages without the usual IE 'do you want to close' prompt, but I need it to work on all windows.  It would seem like this could be merged with this:

'Known bug : don't do right click on an IE icon in the taskbar, it freezes
Set J=CreateObject("Shell.Application")
on error resume next
Do
WScript.Sleep 2000
if instr(ucase(wscript.fullname),"CSCRIPT") Then wscript.echo Now
For L=0 to J.windows.count-1
With J.windows.item(L)
If IsObject(.document.frames) Then
If Not isObject(.document.frames.opener) Then
Else
.document.frames.close
End if
End If
End With
Next
Loop

This code works to close all new pop-ups, but with a prompt.  I am not very good at this, but if you can help me I will study it and maybe help my learning curve. Any ideas? Happy new years!!  :wave:  


DO YOU THINK THIS COULD WORK?

(in reply to TNO)
 
 
Post #: 9
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 12/31/2006 7:18:58 PM   
  TNO


Posts: 1397
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: online
Alright, if you insist on having a vbscript popup blocker...heres what I would do:



      

The only Issues I see with this are:
1.- it'll run forever until you stop it with the task manager
2.-You have to start this manually everytime you start windows
3.-It'll close popups once ever 2 seconds (which you can adjust)
4.-If the popup opens a popup window of its own, then an error will occur (I didn't check wether window.opener was closed or not first)

This is just a proof of concept that could be improved significantly. This is much cleaner than those examples you posted though I think. Maybe one of my colleagues will wander by and slap this bit of code around and spruce it up a bit


< Message edited by TNO -- 12/31/2006 7:24:14 PM >


_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to AngieX)
 
 
Post #: 10
 
 RE: Pop-up blocker parsed in VB script? Can this be scr... - 1/2/2007 6:25:52 AM   
  AngieX

 

Posts: 6
Score: 0
Joined: 12/27/2006
Status: offline
Thank you!  I am going to start experimenting with this now.  Have a safe, happy and joyous 2007! 

-AngieX

(in reply to TNO)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Pop-up blocker parsed in VB script? Can this be scripted? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts