Modifying a URL in Browser before it is sent

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
williamjamieson
Posts: 10
Joined: Fri Apr 23, 2021 6:01 am

Modifying a URL in Browser before it is sent

Post by williamjamieson » Wed Apr 28, 2021 9:43 pm

Hello,

I was just wondering if there was a way to modify the URL say with a different endpoint or params before it is loaded in a browser.

Example: redirect from desktop site to mobile site equivalent. http [not s]: [not slash] [not slash] website [not dot] com/page --> http [not s]:[not slash] [not slash] m. [not] website [not dot] com/page

[[[ NO OTHER QUESTIONS ]]]]

I have been trying the browserBeforeNavigate but it doesn't get triggered when I use it in the IDE. I was hoping to use it to test, but this will be for ios and android only so as long as browserLoadRequest works, then there is an opportunity. However, looking at other threads (from years ago), they were saying that it doesn't always get sent, and one said it only works on iOS. Either way, if it sends a pURL, and I trap it, then navigate to a slightly different URL, would that work without any issues?

Thanks
Last edited by williamjamieson on Thu Apr 29, 2021 6:34 am, edited 1 time in total.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Modifying a URL in Browser before it is sent

Post by Klaus » Wed Apr 28, 2021 10:53 pm

Hi William,
williamjamieson wrote:
Wed Apr 28, 2021 9:43 pm
...
(wow how to comply with the forum link rules...?)
...
due to high volume of spamming, you need to have at least seven postings before you can post links, images etc.
That's how you comply the forum link rules. :-)


Best

Klaus

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Modifying a URL in Browser before it is sent

Post by kdjanz » Thu Apr 29, 2021 3:31 am

We will understand if you now post 6 or 7 short nonsense posts to bring you up to full status and then ask your question again with links to explain what you are trying to do... everyone has to jump through this hoop if you want to use the forum, so we've done it too. :D

Kelly

williamjamieson
Posts: 10
Joined: Fri Apr 23, 2021 6:01 am

Re: Modifying a URL in Browser before it is sent

Post by williamjamieson » Thu Apr 29, 2021 6:33 am

Whoops i think i posted the wrong question. Can you please help me answer the question about livecode. I forgot that lc forced me to create a new forum account so never seen that before.

williamjamieson
Posts: 10
Joined: Fri Apr 23, 2021 6:01 am

Modifying a URL in Browser before it is sent

Post by williamjamieson » Thu Apr 29, 2021 6:36 am

Hello,

I was just wondering if there was a way to modify the URL say with a different endpoint or params before it is loaded in a browser.

Example: redirect from desktop site to mobile site equivalent. http [not s]: [not slash] [not slash] website [not dot] com/page --> http [not s]:[not slash] [not slash] m. [not] website [not dot] com/page

I have been trying the browserBeforeNavigate but it doesn't get triggered when I use it in the IDE. I was hoping to use it to test, but this will be for ios and android only so as long as browserLoadRequest works, then there is an opportunity. However, looking at other threads (from years ago), they were saying that it doesn't always get sent, and one said it only works on iOS. Either way, if it sends a pURL, and I trap it, then navigate to a slightly different URL, would that work without any issues?

Thanks

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Modifying a URL in Browser before it is sent

Post by Klaus » Thu Apr 29, 2021 10:57 am

Hi William,

we understood your question but as I moderator I wanted to clear things first, OK?
[[[ NO OTHER QUESTIONS ]]]]
Come on... 8)

Since the browser does not have a GUI, how do your users "enter" (?) any url?
Maybe you can "hook" there?


Best

Klaus

williamjamieson
Posts: 10
Joined: Fri Apr 23, 2021 6:01 am

Re: Modifying a URL in Browser before it is sent

Post by williamjamieson » Sun May 02, 2021 5:40 am

oh it seemed like my question got completely misunderstood, and was looking like I was about to instigate a thread on url censoring rather than livecode...Things like this happen on forums way too much. So i wasn't sure what to do. I wanted to delete it and start over, but i couldn't figure out how.

But thank you so much for settling it straight klaus!

To answer your question, we have buttons in the webapp. Just <a href> and <button> tags for navigation. When clicked i understand that they create a request within the browser. And on mobile there is a function called "on browserLoadRequest". However, I don't get this message received on the card script where i have it placed (according to the documentation this is where the message is sent.) This was what I was hoping would work as there was a comment that said that if you don't pass the URL it won't navigate, so i thought if you did pass the url modified, it would navigate there. Hopefully this is clear.

Here is an example:

<button href="https..link (dot) com / mypage"></button>
click this

on browserLoadRequest pURL
put "/subpage/" after pURL
pass pURL
end browserLoadRequest

then app goes to https ..link (dot) com / mypage / subpage

Is this the right function to call? Is there something else i should be using?

Thank you so much!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Modifying a URL in Browser before it is sent

Post by jacque » Sun May 02, 2021 9:44 pm

I see a few things. First, you can't pass a variable like that, you can only use "pass" to pass a message. So you need this:

Code: Select all

on browserLoadRequest pURL
  put "/subpage/" after pURL
  pass browserLoadRequest
end browserLoadRequest
But I'm not sure that will change the URL that the browser is trying to load, you'll need to test it.

Also, the browserLoadRequest message is sent to the script that created the browser. If that was done in the card then the handler is already in the right place. If the browser was created with a button then the handler needs to go there. If the browser was created in the stack script then then I'd move it there.

The dictionary lists two related messages, browserLoadRequest and browserLoadRequested. For the one you're using, it will only fire if "The browserLoadRequest is only sent if delayRequests has been set to true." So check that. The second message variation, browserLoadRequested, "is sent to the object containing the script that created the mobile browser control after a url has been requested and passed for loading." I've never used this message but it implies that if you intercept browserLoadRequest then you also need browserLoadRequested -- depending on the value of delayRequests.

It's somewhat confusing and I've never had to deal with it, but I think if you set delayRequests to true when creating the browser and include both types of browserLoadRequest[ed] message handlers then it should work.

EDIT: Re-reading browserLoadRequested in the docs, I'm not sure now that's the answer either. It may be sent after the URL is already committed in the browser. My answer may be mostly useless, except for the part about passing the message rather than the variable, and setting delayRequests to true.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

williamjamieson
Posts: 10
Joined: Fri Apr 23, 2021 6:01 am

Re: Modifying a URL in Browser before it is sent

Post by williamjamieson » Fri May 14, 2021 11:50 pm

No, that was a very detailed answer that confirmed that the situation is indeed a little confusing, and that if it were to work, that i am using the right message for it to happen. Thank you so much for taking the time to detail that out for me.

In regards to the browser, you mentioned where it is created. But the browser is a widget that is created in the IDE which is neither an object, a card, or a stack. I would think that it would either be the widget itself that gets the message and if not captured then should eventually get passed to the stack. However, i didn't get anything on the card when it tried it. Do i need to use MobileControlCreate in order for this to work?

Thanks

williamjamieson
Posts: 10
Joined: Fri Apr 23, 2021 6:01 am

Re: Modifying a URL in Browser before it is sent

Post by williamjamieson » Sat May 15, 2021 12:15 am

So i found the issue. Gosh I am so out of the loop. Been many years since I opened livecode. I saw it was good for mobile, but forgot to check the OS. It says for iOS only. But I need this feature for Android too... Hm. Will have to think of something.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Modifying a URL in Browser before it is sent

Post by FourthWorld » Sat May 15, 2021 12:45 am

Maybe simpler to build the web site using responsive design so it works on all devices.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”