cancel browser widget navigation - possible?

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: cancel browser widget navigation - possible?

Post by [-hh] » Wed Oct 24, 2018 8:49 am

You can set the contents as usual.
How do you script this update?

If using the htmltext then this works:

Code: Select all

on browserNavigateBegin pURL
    set htmltext of me to myHTML() 
end browserNavigateBegin
If using JS then this works:

Code: Select all

on browserNavigateBegin pURL
    do myJS() in widget "browser"
end browserNavigateBegin
If using an URL then this works:

Code: Select all

on browserNavigateBegin pURL
    set URL of me to myURL()
end browserNavigateBegin
shiftLock happens

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: cancel browser widget navigation - possible?

Post by rodneyt » Wed Oct 24, 2018 9:35 am

This technically works, but forces my single page app to reload. This ejects user from their editing session (tabs/docs open in the web app)...

Any thoughts for a solution which doesn't result in my web app being reloaded?
[-hh] wrote:
Wed Oct 24, 2018 8:49 am
If using an URL then this works:

Code: Select all

on browserNavigateBegin pURL
    set URL of me to myURL()
end browserNavigateBegin
~ Rodney

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: cancel browser widget navigation - possible?

Post by [-hh] » Wed Oct 24, 2018 10:39 am

Perhaps this is the simplest method before you add more new side conditions :)

1. Add a global to your JS:

Code: Select all

<head><script>var myGlobal=true;</script></head>
2. Add the following onclick handler to your links, for example:

Code: Select all

<a href='http://www.hyperhh.org' onclick='return myGlobal;'>Hi</a>
3. In LiveCode only add the following to your session start:

Code: Select all

do "myGlobal=false" in widget "browser"
Then your links don't work in LiveCode but in an ordinary browser.
For testing you could make a check button "Links Enabled", scripted with

Code: Select all

on mouseUp
  do ("myGlobal="&the hilite of me) in widget "browser"
end mouseUp
[In case you have't seen how to navigate back/forward:

Code: Select all

go <back|forward> in widget "browser"
Of course this is only working if the widget has URLs available].
shiftLock happens

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: cancel browser widget navigation - possible?

Post by AndyP » Wed Oct 24, 2018 2:07 pm

I still do not understand why this does not work for you?

The browser widget URL is set to 2108.co.uk in its properties pallet.

on browserNavigateBegin pUrl
if "2108.co.uk" is not among the words of pUrl then
exit to top
end if
end browserNavigateBegin

See the screenvid of it in my setup. Win 10 LC 8.14 Community, that shows it working.

http://2108.on-rev.com/nextcloud/index. ... 3HKH2qkmPq

Do you not see the same results? Links from the domain 2108.co.uk are actioned but outside links are ignored.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: cancel browser widget navigation - possible?

Post by rodneyt » Wed Oct 24, 2018 10:52 pm

Andy, my guess is that on MacOSX we're using a different browser (maybe Safari?) than on windows (which my guess, is using Chromium?). That could account for different behaviour.
AndyP wrote:
Wed Oct 24, 2018 2:07 pm
I still do not understand why this does not work for you?

The browser widget URL is set to 2108.co.uk in its properties pallet.

on browserNavigateBegin pUrl
if "2108.co.uk" is not among the words of pUrl then
exit to top
end if
end browserNavigateBegin

See the screenvid of it in my setup. Win 10 LC 8.14 Community, that shows it working.

http://2108.on-rev.com/nextcloud/index. ... 3HKH2qkmPq

Do you not see the same results? Links from the domain 2108.co.uk are actioned but outside links are ignored.

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: cancel browser widget navigation - possible?

Post by rodneyt » Wed Oct 24, 2018 10:55 pm

There's always:

on browserNavigateBegin pUrl
if not (pUrl contains "DOMAIN") then
do "window.stop();" in widget "X" of stack "Y"
exit to top
end if

:-)

Of course it's not really a solution as it stops all Javascript from running in the page....
But it does in fact also stop the page navigating away....

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: cancel browser widget navigation - possible?

Post by AndyP » Thu Oct 25, 2018 8:38 am

Andy, my guess is that on MacOSX we're using a different browser (maybe Safari?) than on windows (which my guess, is using Chromium?). That could account for different behaviour.
Maybe, then there should probably be a bug report raised as the browser widget is supposed to function in the same way across all platforms? I've just looked in the dictionary and can see no reference to differences on Windows or Mac.

Can another Mac and Windows user please test this.

The browser widget URL is set to 2108.co.uk in its properties pallet.

on browserNavigateBegin pUrl
if "2108.co.uk" is not among the words of pUrl then
exit to top
end if
end browserNavigateBegin
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: cancel browser widget navigation - possible?

Post by bogs » Thu Oct 25, 2018 2:11 pm

Heya Andy,

I tried, since I sort of have both environments to play with, but am not getting reliable results from the later IDEs.

Mac 10.6.5 Lc 8.1.8 (latest I can run there) -
test doesn't appear to work, but am not able to confirm that I am not screwing something up. Tested by setting up the stack the way you listed, slight modifications afterwards.

Code: Select all

// browser widget code ...
on browserNavigateBegin pUrl
	if "2108.co.uk" is not among the words of pUrl then answer "Not a 2108 address"
browserNavigateBegin pUrl

// placed 2 buttons below browser widget, set the labels to [www.google.com] and [2108.co.uk]...
// code in card script...
on mouseUp
	set the url of widget "Browser" to "https://" & the label of the target
end mouseUp
..1. no matter which button I clicked, the answer dialog showed up reporting that this is not a 2108 address.
osxTest [Running] - Oracle VM VirtualBox_081.png
Google...
osxTest [Running] - Oracle VM VirtualBox_080.png
2108....
I resolved this was changing the line "if "2108.co.uk" is not among the words of pUrl then answer "Not a 2108 address" to the following -

Code: Select all

if "2108.co.uk" is not among the characters of pUrl then answer "Not a 2108 address"
I don't have a windows box with a connection to the internet, so couldn't perform the test on one of those systems, but will setup one just to see.
Image

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3975
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: cancel browser widget navigation - possible?

Post by bn » Thu Oct 25, 2018 2:32 pm

Hi Andy,
if "2108.co.uk" is not among the words of pUrl then
this does not work because "2108.co.uk" is 3 words. And you could only test one word with "is among the words".

but still even with

Code: Select all

if not (pURL contains "2108.co.uk") then
it does not work, i.e. is does not prevent going to e.g. Twitter from your page because Twitter" has "2108.co.uk in its URL as referrer.

After a little experimentation I can stop leaving the website using

Code: Select all

on browserNavigateBegin pUrl
   --put pURL && the milliseconds & cr after msg
   if not (pURL contains  "http://2108.co.uk") then
      set the htmlText of widget 1 to "<p>Patience, we will be back</p>"
      set the url of widget 1 to "http://2108.co.uk"
   end if
end browserNavigateBegin
tested using the Twitter link on your homepage.

I know almost nothing about the browser widget so I am of little help here.


Kind regards
Bernd

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

Re: cancel browser widget navigation - possible?

Post by jacque » Thu Oct 25, 2018 5:33 pm

this does not work because "2108.co.uk" is 3 words.
Were you thinking of truewords?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3975
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: cancel browser widget navigation - possible?

Post by bn » Thu Oct 25, 2018 5:47 pm

No, I probably did not think at all. Actually it did not work and I thought the punctuation mark was the end of a word. But it turned out that it did not work because there was like "http://2108.co.uk/" and similar and that messed up "word" - boundaries.

And yes, "2108.co.uk" is one word as long as it is preceded and followed by space.

Thank you Jaque

Kind regards
Bernd

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: cancel browser widget navigation - possible?

Post by bogs » Thu Oct 25, 2018 9:54 pm

OOoooo, I like Bernd's spin better than mine, I couldn't figure out why the twitter link was going with the way I set it up. Good explanation Bn!
Image

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

Re: cancel browser widget navigation - possible?

Post by jacque » Thu Oct 25, 2018 10:24 pm

bn wrote:
Thu Oct 25, 2018 5:47 pm
No, I probably did not think at all.
LOL. I often have the same problem. :) It gets worse with age.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”