Block specific site and show custom content? RRS feed

  • Question

  • I have this vbscript which detects if a specific web page is loaded on an IE tab and shows a small phrase instead of the page contents. The problem is that if I choose to see the source code, I can see the code of the initial page. Is it possible to get rid of the initial code at all?

    Also this code is not working with Edge. Can it be modified to work with Edge as well?

    (For example, is tried to do it on the google site.)

    Dim  Web, wb, browse
    Set Web = CreateObject("Shell.Application")
    Set Web = Web.Windows
    If Web.count = 0 then
      set wb = Nothing
      set browse = Nothing
      For i = 0 To Web.count-1
        If TypeName(Web.Item(i).Document) = "HTMLDocument" And Instr(1, Web.item(i).LocationUrl, "google", vbTextCompare) > 0 Then
          set browse = Web.Item(i)
          set wb = Web.Item(i).Document
          wb.body.innerHTML = ""
          wb.body.outerHTML = "Access to this site is denied."
          exit For
        End If
    End If

    • Edited by doctor-M Sunday, August 7, 2016 7:16 AM
    Sunday, August 7, 2016 7:15 AM

All replies

  • There is no VBA interface to Edge and there are no plans to create one so IE11 is it.  There is a Selenium interface to Edge.  Someone created a VBA interface to Selenium.   I recommend you use it.  It supports Firefox, Chrome, IE and Edge. It is much better than Microsoft Internet Controls.

    Note: Version works with Firefox 46.0.1 but not 47 or 48.

    Sunday, August 7, 2016 1:45 PM
  • Thank you for your reply. As I had two questions, is there any way to get rid of the initial code of the page initially opened in IE 11 and see only the content that I pass through the script?

    This script works with IE 11 but not as would like to.

    • Edited by doctor-M Sunday, August 7, 2016 2:14 PM
    Sunday, August 7, 2016 2:09 PM
  • You need to wait until the webpage has loaded and then set the innerHTML.  You are setting it before the page has loaded.

    IE.Navigate "http://..........."
    Do While IE.Busy Or IE.ReadyState <> 4

    set innerHTML here

    Sunday, August 7, 2016 6:21 PM
  • I wasn't clear enough and I apologize for that. The page is not loaded via script. The page is loaded physically, by double clicking browser's icon and typing the desired url in the address bar. In my tests, the script runs many seconds after the page's loading. Sometimes, it runs minutes after the loading and there is not such an issue.
    Sunday, August 7, 2016 6:52 PM