Copy URL into a text field

Hello, all,

I need to do a simple task and got stuck. I’ve searched the online documentation and cannot find an answer.

How can I determine via code the URL of the currently open webpage opened in the HTMLViewer?

Thank you in advance,


Hi Val,
There is no property on the HTMLViewer for returning the page currently being viewed, but you can do this yourself.
First: add a property to the window or container that houses the HTMLViewer. We’ll call currentURL

Public Property currentURL As String

Next: Add the DocumentComplete event handler to your HTMLViewer instance and add the following code:

currentURL = URL

Now, anytime a navigation event occurs, currentURL should get you there. Sometimes, due to the way sites will load, you’ll see multiple accesses in a short time. Usually the first one is the one you want, so you check the amount of time passed between first and subsequent requests.

I do this with another property:

Public Property firstAccess As Double

Then change the DocumentComplete handler’s code:

if (System.Microseconds - firstAccess) / 1000000 >= 1 then
  currentURL = URL
  firstAccess = System.Microseconds
end if

This uses one second as the basis for updating, but you could easily modify that to any other value that may suit your needs.

1 Like

Hi, Anthony,

Thank you for your very clear explanation.

I am developing a simple training application for students. After the students go through the procedure several times, they will be taken to the SurveyMonkey-based quiz.

I want the window with the quiz to close automatically as soon as the quiz is complete. As far as I know, after the survey is completed, SurveyMonkey automatically goes to their promotional webpage.

I will use the method you’ve described to recognize that the HTMLViewer is not on the quiz page any more, and that will trigger the windows to close and return back to the training software main window.

Thank you again for your help.


1 Like