WebBrowser Get Domain Name Question

Posted on 2009-12-26
Medium Priority
Last Modified: 2012-05-08
Hi all,

How can I get the current domain url in a twebbrowser leaving out any filenames please?

For example: If the current url is: http://www.mysite.com/somepage.html

then I need to get the url without the filename..so it would leave:


hope you can help


p.s: The url I hold in a TEdit

Question by:ST3VO
LVL 23

Accepted Solution

Ferruccio Accalai earned 2000 total points
ID: 26126144
First of all, use the property LocationUrl.
Then, to extract the domain, use the attached function.

//From Delphi7 PosEx is in StrUtils 
//if you use Delphi6 Use this PoseEx Function, else just add StrUtils to the uses clause

function PosEx(Substr: string; S: string; P: Integer): Integer;
  if P <= 0 then Result := 0
  else Result := Pos(Substr, Copy(S, P, Length(S)));
  if Result <> 0 then Result := Result + P - 1;

//This is the Funtion to extract the domain from the url
//Use it calling YourDomain := GetDomain(YourWebBrowser.LocationUrl);
Function GetDomain(URL:String):String;
 if Pos('http://',URL) = 0 then result := URL
      result := Copy(URL,1,PosEx('/', URL, 8)-1);
    while (Length(result) > 0) and (result[Length(result)] = '/') do
      Delete(result,Length(result),1); // strip trailing /

Open in new window


Author Closing Comment

ID: 31670130
Perfect thanks!!! :o)

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

862 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