Solved

Open a URL with Internet Explorer in a new tab (not a new window)

Posted on 2016-10-06
1
95 Views
Last Modified: 2016-10-07
I am trying to get an already running instance of Internet Explorer to add a new tabbed page. This is the Delphi code I start with.:

var
  Temp : String;
begin
  if FileExists('C:\Program Files (x86)\Internet Explorer\iexplore.exe') then begin
    Temp := '"C:\Program Files (x86)\Internet Explorer\iexplore.exe"';
  end;
  if FileExists('C:\Program Files\Internet Explorer\iexplore.exe') then begin
    Temp := '"C:\Program Files\Internet Explorer\iexplore.exe"';
  end;
  ShellExecute(Handle, 'open', PChar(Temp), PChar('http://google.com'), nil, SW_SHOW);
end;

Open in new window


Although this code does display the URL (http://google.com) in IE, it does so by launching a new instance (new window) of IE rather than in a new tabbed page to the already running instance of IE.  How can I do the latter?
0
Comment
Question by:Fontographer
1 Comment
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 41833123
I've managed to run multiple tabs using IE ole automation. First, check if iexplore.exe is running. If yes - then use Navigate2 function from that runing instance, but if not found - start new instance...
uses ComObj;
...
//https://msdn.microsoft.com/en-us/library/dd565688(v=vs.85).aspx
const
  navOpenInNewWindow = 1;
  navNoHistory = 2;
  navNoReadFromCache = 4;
  navNoWriteToCache = 8;
  navAllowAutosearch = 16;
  navBrowserBar = 32;
  navHyperlink = 64;
  navEnforceRestricted = 128;
  navNewWindowsManaged = 256;
  navUntrustedForDownload = 512;
  navTrustedForActiveX = 1024;
  navOpenInNewTab = 2048;
  navOpenInBackgroundTab = 4096;
  navKeepWordWheelText = 8192;
  navVirtualTab = 16384;
  navBlockRedirectsXDomain = 32768;
  navOpenNewForegroundTab = 65536;

procedure RunIEUrl(sURL: String; param: OleVariant);
var
  i: Integer;
  ShellWindows: OleVariant;
  ShellApplication: OleVariant;
  IE: OleVariant;
begin
  IE := Unassigned;
  //find running instance - using win shell
  ShellApplication := CreateOleObject('Shell.Application');
  if not VarIsEmpty(ShellApplication) then
  begin
    ShellWindows := ShellApplication.Windows;
    for i := 0 to ShellWindows.Count - 1 do
    begin
      if UpperCase(ExtractFileName(ShellWindows.Item(i).FullName)) = 'IEXPLORE.EXE' then //check exe name
      begin
        IE := ShellWindows.Item(i);
        IE.Navigate2(sURL, param);
        Break;
      end;
    end;
  end;

  //not found running instance - run new instance
  if VarIsEmpty(IE) then
  begin
    IE := CreateOleObject('InternetExplorer.Application');
    IE.Visible := true;
    IE.Navigate2(sURL);
  end
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RunIEUrl(Edit1.Text, navOpenInNewTab);
end;

Open in new window


Fill Edit1 with a web site url....
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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