How do I get the current URL of the page loaded in the browser widget

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 494
Joined: Thu Sep 04, 2008 6:23 am

How do I get the current URL of the page loaded in the browser widget

Post by jameshale » Sat Nov 08, 2025 8:22 am

Hi all,

I am stumped at determining the URL of the current page being displayed in the browser widget.

I have a stack with the widget and I set its URL

The page displays and I can interact with it.
Great.

I then click on a link within the page (actually on a pop upwundow) and go to another page.

How do I get the URL of this page?

Looking at the dictionary it seems I could respond to "browserDocumentLoadComplete pUrl"

But I don't know how to use it.
I am assuming it can be located in a script in the card.
So I tried...

Code: Select all

on browserDocumentLoadComplete pUrl
   put purl
end browserDocumentLoadComplete
But nothing.

Any ideas?

Klaus
Posts: 14267
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How do I get the current URL of the page loaded in the browser widget

Post by Klaus » Sat Nov 08, 2025 10:24 am

Hi James,

this works for me:

Code: Select all

on browserDocumentLoadBegin tUrl
   put tUrl
end browserDocumentLoadBegin
However "browserDocumentLoadComplete" also worked for me, but only tested in the IDE.

Best

Klaus

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 494
Joined: Thu Sep 04, 2008 6:23 am

Re: How do I get the current URL of the page loaded in the browser widget

Post by jameshale » Sat Nov 08, 2025 1:02 pm

Hi Klaus,
No still nothing here.
Was your script in the card?

James

Klaus
Posts: 14267
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How do I get the current URL of the page loaded in the browser widget

Post by Klaus » Sat Nov 08, 2025 1:07 pm

Yes, script was in the card.

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 494
Joined: Thu Sep 04, 2008 6:23 am

Re: How do I get the current URL of the page loaded in the browser widget

Post by jameshale » Sun Nov 09, 2025 6:12 am

Seems like it is the site I am going to. I need to invesitage more.

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 172
Joined: Tue Feb 23, 2010 10:53 pm

Re: How do I get the current URL of the page loaded in the browser widget

Post by bobcole » Tue Nov 11, 2025 9:22 pm

This intrigued me so I did some research.
It looks like there is a direct way of getting the URL of the browser.

Code: Select all

on getTheURL
   get the URL of widget "MyBrowser"
   put it & return after field "The URL"
end getTheURL   
I hope this works for you.
Bob Cole

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 494
Joined: Thu Sep 04, 2008 6:23 am

Re: How do I get the current URL of the page loaded in the browser widget

Post by jameshale » Tue Nov 11, 2025 11:54 pm

Thanks Bob for the thought.
Interestingly using your handler only returned "false"!!!
Removing the "and return" gave me a URL.
Unfortunatley this URL did not change when I changed pages in the widget.
Bizarrely nothing I did changed it. It was correct for the site, as tested in an actual browser but I couldn't get it to change for the widget no matter what I did on the page.
I also tried handlers using all of the messages associated with the widget.
none of them triggered when I clicked on links in the widget.
Yet the page displayed did.

In doing the same in Safari, the url of the page does change with every click.
So I am flummoxed as to why the widget fails to pick this change up even though it changes what it displays.

BTW on other sites things seem fine, it must be something to do with the way this particular site/page is constructed.

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 172
Joined: Tue Feb 23, 2010 10:53 pm

Re: How do I get the current URL of the page loaded in the browser widget

Post by bobcole » Thu Nov 13, 2025 12:02 am

This works on my system. take a look.
If it doesn't work for you that means something else is the problem.
I am using a Mac M1 laptop, lots of RAM and disk space.
What system are you using?
Bob
Browser Widget.livecode.zip
(1.51 KiB) Downloaded 5 times

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 494
Joined: Thu Sep 04, 2008 6:23 am

Re: How do I get the current URL of the page loaded in the browser widget

Post by jameshale » Thu Nov 13, 2025 12:31 am

Hi Bob,
needed to enter the URL in the widget's property inspector for it to register (go figure?)
However on the site I am interested in no change in the reported URL.
I looked at the script and noticed you are expecting a "browserDocumentLoadComplete" message (as did I), however the site I am on doesn't trigger it.
Each page has a next/prev arrow which does change pages but the widget although displaying the new page sends no message. As I mentioned before it I works fine using an actual browser. Changing pages is reflected in the URL show in the browsers address bar.
Something weird in my site of interest or broken in the widget.
BTW the site I am looking at is <https://acim.org/acim/en>

Post Reply