How can I disable a certain Javascript block in WebBrowser

Posted on 2006-04-29
Last Modified: 2012-06-27
Some site has Hacker Code with Javascript and VBScript and I try to find a way to protect IE by avoiding these Hacker Code Block execute.
I had wrotten a BHO to monitor my IE, but how can I disable a certain javascript/vbscript block before the script executing in IE ?
Question by:xlt77
    LVL 13

    Expert Comment

    one way would be to have a proxy to avoid downloading such blocks
    LVL 2

    Author Comment

    I won't to use third-party product, and I just want to implement it with delphi.
    LVL 26

    Expert Comment

    Not sure if it will help because I don't have time to test it.
    Please check item No. 2 here:

    I *know* it says to stop javscript errors but you can override all javascript
    in the same manner. Only problem is that you will need to know *WHICH*
    script to block. I'll leave that up to you.
    LVL 2

    Author Comment

    I am sorry that I show my question not clearly.
    When I navigate a web site on internet , I want to forbidden a certain javascript block before this script code execute.
    Forbidden it before executing ,  not dealing it on Runtime Error
    LVL 26

    Expert Comment

    I'm sorry you did not READ my answer correctly...

    "but you can override all javascript in the same manner"

    LVL 2

    Author Comment

    Yeah, EddieShipman, thanks your commence!
    I had tried your answer, in fact , the script has run before the documentcomplete event.

    =====Here is the html=======
    <script type="text/javascript" src="test1.js"></script>
    <script type="text/javascript" src="test2.js"></script>

      alert('This is a test');

    This is a test

    =====Delphi code =========
    procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);

    And the result shows 'This is a test' is been displayed before the scripts length.

    and I tried this code in DownLoadComplete event, I found DownloadComplete event ocused before javascript executing, but in DownloadComplete event , I can get only 1 Scripts item. Thus , in downloadComplete event
    webbrowser1.OleObject.document.all.tags('SCRIPT').length  =  1

    It's so confused that I can't get the whole scripts code before IE auto execute them.

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now