请问如何在WebBrowser控件中不让链接在新窗口打开!
即:点击_Blank的超级链接后,不让链接在新的窗口打开,在原来的位置打开!
谢谢!

解决方案 »

  1.   

    procedure NewWin_LinkClick;
    var
      doc:IHTMLDocument2;
      all:IHTMLElementCollection;
      len,i,flag:integer;
      item:IHTMLElement;
      vAttri:Variant;
    begin
    try
        //获得Webbrowser对象中的文档对象
        doc:=IHTMLDocument2(你的webbrowser名称.Document);
        //获得文档中所有的HTML元素集合
        all:=doc.Get_all;
        len:=all.Get_length;
        //访问HTML元素集合中的每一个元素
        for i:=0 to len-1 do
        begin
          item:=all.item(i,varempty) as IHTMLElement;
          //如果该元素是一个链接
          flag:=0;
          vAttri:=item.getAttribute('protocol',flag); //获得链接属性
            //如果是http链接则将链接的目标地址添加到ComboBox1
        if (vAttri ='http:') or (vAttri ='file:') then
        begin
            vAttri:=item.getAttribute('target',flag);
            VAttrilist.Lines.Insert(i,vAttri);
            item.setAttribute('target','_blank',flag);
        end
        end;
      except
      end;
     end;