document.location not working in VBS RRS feed

  • Question

  • I have a VBS script in an HTA in which I use document.location to detect the current web adress of an IE window, but each time I run the code it outputs: "Permission denied".

    The code below is supposed to open "https://www.youtube.com/?gl=EN&hl=en" in IE, and (when finished loading) open a MsgBox if the web adress (IE.document.location) actually is "https://www.youtube.com/?gl=EN&hl=en".

    Note: My original code is much longer than this, I just made this example code to show you what my problem is.

    <script type="text/vbscript">
    Sub Wait(Time)
      Dim wmiQuery, objWMIService, objPing, objStatus
      wmiQuery = "Select * From Win32_PingStatus Where Address = '' AND Timeout = " & Time
      Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
      Set objPing = objWMIService.ExecQuery(wmiQuery)
      For Each objStatus in objPing
    End Sub
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "https://www.youtube.com/?gl=EN&hl=en"
    Do Until IE.ReadyState = 4
    Set url = IE.document.location
    If url = "https://www.youtube.com/?gl=EN&hl=en" Then
      X = MsgBox("You're on Youtube")
      X = MsgBox("You're not on Youtube")
    End If

    • Edited by Cesar CAL Tuesday, August 8, 2017 8:02 AM
    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:57 PM This is not "fix/debug/rewrite my script for me" forum
    Tuesday, August 8, 2017 8:00 AM

All replies

  • "permission denied" on what?


    Tuesday, August 8, 2017 8:16 AM
  • Just "Permission denied". If I change "IE.document.location" to "IE.document.location.href" though, I get "Permission denied: IE.document.location.href". http://imgur.com/a/IP2o4

    Tuesday, August 8, 2017 8:40 AM
  • url = IE.document.location

    "Set" not used for strings.


    Tuesday, August 8, 2017 10:06 AM
  • I really thought (and hoped) removing "set" would work, but unfortunately, it still gives me the same error. It seems like the error is "IE.document.location" itself and not how I declare or use the variable. Do you know if there's any alternative to "document.location", or any other way to find out the web adress?
    • Edited by Cesar CAL Tuesday, August 8, 2017 3:24 PM
    Tuesday, August 8, 2017 11:00 AM