• Delphi让网页只允许在WebBrowser里面打开


    [添加组件]

    添加 Internet->WebBrowser //显示网页

    [添加事件]

    鼠标点击WebBrowser组件,在Events事件选项框中找到.

    OnNewWindows2,OnStatusTextChange.双击添加事件.

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OleCtrls, SHDocVw;
    
    type
      TForm1 = class(TForm)
        WebBrowser1: TWebBrowser;
        procedure FormCreate(Sender: TObject);
        procedure WebBrowser1NewWindow2(Sender: TObject; var ppDisp: IDispatch;
          var Cancel: WordBool);
        procedure WebBrowser1StatusTextChange(Sender: TObject;
          const Text: WideString);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      NewURL:String;
      //定义一个全局变量,让这个全局变量来获取最新的连接地址.
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
        WebBrowser1.Navigate('http://www.cnblogs.com/')
        //默认打开博客园
    end;
    
    procedure TForm1.WebBrowser1NewWindow2(Sender: TObject;
      var ppDisp: IDispatch; var Cancel: WordBool);
    begin
        Cancel:=true;
        //对话框,这个可以这么理解.
        WebBrowser1.Navigate(NewURL);
        //读取新的地址,并加载.
    end;
    
    procedure TForm1.WebBrowser1StatusTextChange(Sender: TObject;
      const Text: WideString);
    begin
        NewURL:=text;
        //Url地址发生改变,存到全局变量当中.
    end;
    
    end.
  • 相关阅读:
    [Leetcode] ZigZag Conversion
    [Leetcode] Wildcard Matching
    [Leetcode] 4Sum
    [Leetcode] Word Break II
    [Leetcode] Best Time to Buy and Sell Stock III
    [Leetcode] Permutation Sequence
    [Leetcode] Surrounded Regions
    [Jobdu] 题目1522:包含min函数的栈
    CUDA2.1-原理之索引与warp
    opencv8-GPU之相似性计算
  • 原文地址:https://www.cnblogs.com/windson/p/12521063.html
Copyright © 2020-2023  润新知