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: 14268
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: 14268
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: 173
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: 173
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 43 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>

SparkOut
Posts: 2966
Joined: Sun Sep 23, 2007 4:58 pm

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

Post by SparkOut » Thu Nov 13, 2025 8:01 pm

Sounds like the site of interest is dynamically creating/changing content. This is happening all over the internet, making it tricky to use a static interface within LC to manage/manipulate the content.
Hermann (sadly no longer with us) here has some amazing stacks that leverage javascript within LC browsers to do some incredible interactions. I'm not sure what contributions of his still remain, and how any ofvthdm might be generalised to your requirements. Otherwise the only thing possible is to investigate the specific site and work out what controls are happening and maybe devise a way of making the dynamic responses.
I don't mind volunteering to take a look and seeing if I can work anything out, but make no promises as to timeframe nor claims as to chances of success.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10399
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Thu Nov 13, 2025 8:40 pm

I miss Hermann. But all his posts are still here.

Craig

SparkOut
Posts: 2966
Joined: Sun Sep 23, 2007 4:58 pm

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

Post by SparkOut » Thu Nov 13, 2025 9:17 pm

dunbarx wrote:
Thu Nov 13, 2025 8:40 pm
But all his posts are still here.
Unfortunately there is a huge amount redacted from here and as much or more missing from his hosted collections / no longer hosted :(
A great loss, personally and productively.
The saddest is the personal loss. I remember a few private conversations. A fine gentleman.

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 173
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 » Fri Nov 14, 2025 4:22 am

I spent some time with your website of interest: https://acim.org/acim/en
I don't have an answer as to why that website doesn't send the browserDocumentLoadBegin/Complete messages.
I have some observations, however.
1 - The web pages addresses can be seen by clicking on Terms of Service then return to the website. I used the Terms of Service page as an example, other pages may do the same thing. Note the address at the bottom after the Return button is clicked. The web address shows at the bottom of the screen.
2 - Did you know that the web pages are directly addressable? I put several of them into my Browser Widget app (see attached).

I don't know why this does not work when the page forward / page backward buttons are pressed.
Maybe someone else can figure this out.
Bob
Browser Widget 2.livecode.zip
(1.83 KiB) Downloaded 35 times

Post Reply