You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

需求:用VBScript获取输入URL跳转后弹窗页面的目标URL

Hey there, I’ve put together a VBScript solution that can capture the popup target URL when loading http:\URL_MAIN. This script leverages Internet Explorer’s COM automation to listen for new window events and grab the URL of the popup as soon as it loads.

VBScript Code
Option Explicit

Dim objIE, popupURL, timeout, startTime
Dim mainURL : mainURL = "http:\URL_MAIN" ' Replace with your actual main URL

' Initialize tracking variables
popupURL = ""
timeout = 10 ' Wait up to 10 seconds for the popup (adjust as needed)
startTime = Timer

' Create hidden Internet Explorer instance
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False ' Run in background; set to True if you want to visualize the process
objIE.Silent = True ' Suppress script errors and unnecessary prompts

' Attach event handler to catch new window creation
Set objIE = WScript.CreateObject(objIE, "IE_")

' Navigate to the main URL that triggers the popup
objIE.Navigate mainURL

' Wait for popup to appear or hit timeout
Do While popupURL = "" And (Timer - startTime) < timeout
    WScript.Sleep 500 ' Pause 500ms between checks to reduce resource usage
Loop

' Output the result
If popupURL <> "" Then
    WScript.Echo "Popup Target URL: " & popupURL
    ' You can modify this to write the URL to a file or return it to another process
Else
    WScript.Echo "Timeout: No popup detected within " & timeout & " seconds."
End If

' Clean up IE instances to avoid lingering processes
objIE.Quit
Set objIE = Nothing

' Event handler that triggers when a new window (popup) is opened
Sub IE_NewWindow2(ByRef ppDisp, ByRef Cancel)
    ' Create a new IE object to handle the popup
    Dim popupIE
    Set popupIE = CreateObject("InternetExplorer.Application")
    Set ppDisp = popupIE
    
    ' Wait a short moment for the popup to fully load its URL
    WScript.Sleep 1000
    
    ' Capture the popup's target URL
    popupURL = popupIE.LocationURL
    
    ' Close the popup immediately after capturing the URL
    popupIE.Quit
    Set popupIE = Nothing
End Sub
Key Details
  • Event-Driven Capture: The IE_NewWindow2 event fires the moment a new window (your popup) is spawned. We use this to intercept and grab the popup’s URL right after it loads.
  • Timeout Protection: The script waits up to 10 seconds (adjustable via the timeout variable) for the popup to appear, preventing it from hanging indefinitely if something goes wrong.
  • Background Execution: Setting objIE.Visible = False runs IE in the background. If you need to debug the process, switch this to True to see the browser windows.
  • Cleanup: The script quits both the main IE instance and the popup after capturing the URL to avoid leaving unused processes running on your system.

内容的提问来源于stack exchange,提问作者Punit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:29:17