cancel browser widget navigation - possible?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
cancel browser widget navigation - possible?
Is anyone aware of a way to cancel navigation in the browser widget? I want to detect attempts to navigate away from my app in the browser widget and handle these differently (for example, opening them in another browser instance). In my app these navigations normally target a new tab/window, but in browser widget they navigate away from my single page app.
I'm looking for Livecode (rather than Javascript) solutions to this issue.
I found a discussion on same topic (to find it, search google: browser widget,"cancel navigation",livecode ) I can't post direct URL here as forum rules prohibit posting URLs to the forum (why? very annoying...)
Seems like not being able to detect/cancel/manage navigation in the browser widget is an issue that should be addressed....
~ Rodney
I'm looking for Livecode (rather than Javascript) solutions to this issue.
I found a discussion on same topic (to find it, search google: browser widget,"cancel navigation",livecode ) I can't post direct URL here as forum rules prohibit posting URLs to the forum (why? very annoying...)
Seems like not being able to detect/cancel/manage navigation in the browser widget is an issue that should be addressed....
~ Rodney
Re: cancel browser widget navigation - possible?
Hi Rodney,
Are you writing about this link?
http://runtime-revolution.278305.n4.nab ... 21826.html
Al
Are you writing about this link?
http://runtime-revolution.278305.n4.nab ... 21826.html
Al
Re: cancel browser widget navigation - possible?
Yes that's the previous discussion on this topic I found - and the proposed solutions are pretty hacky and impractical IMO.
(Re adding links to posts, I think until I have posted enough times to this forum it is suppressing my ability to add hyperlinks to posts...)
~ R
(Re adding links to posts, I think until I have posted enough times to this forum it is suppressing my ability to add hyperlinks to posts...)
~ R
Re: cancel browser widget navigation - possible?
One thing I have discovered I can do is monitor the popstate event by adding a listener thus:
put "window.onpopstate = function(event) {" & return &\
"liveCode.jsCallback('popstate',document.location);" & return&\
"}" into tScript
... then do tScript in widget.
Once called as user navigates around content within my SPA, I will get events returned to my jsCallback handler as an array. This interested me as I thought I would just get the location, instead it seems to return the event array (haven't figured out why yet).
on jsCallback pMessage,pValue
...
switch pMessage
case "popstate"
#pValue is returned object
set the label of stack "ob3-study" to "OB3 - "& pValue["hash"]
Unfortunately this won't detect navigation AWAY from my app. But it's still a useful step forwards...
~ Rodney
put "window.onpopstate = function(event) {" & return &\
"liveCode.jsCallback('popstate',document.location);" & return&\
"}" into tScript
... then do tScript in widget.
Once called as user navigates around content within my SPA, I will get events returned to my jsCallback handler as an array. This interested me as I thought I would just get the location, instead it seems to return the event array (haven't figured out why yet).
on jsCallback pMessage,pValue
...
switch pMessage
case "popstate"
#pValue is returned object
set the label of stack "ob3-study" to "OB3 - "& pValue["hash"]
Unfortunately this won't detect navigation AWAY from my app. But it's still a useful step forwards...
~ Rodney
Re: cancel browser widget navigation - possible?
Executing this in Chrome console within a website will prompt you if you attempt to navigate away:
window.addEventListener('beforeunload', function (e) {
var confirmationMessage = '\o/';
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
Has anyone been able to get the beforeunload event to work with the browser widget?
~ Rodney
window.addEventListener('beforeunload', function (e) {
var confirmationMessage = '\o/';
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
Has anyone been able to get the beforeunload event to work with the browser widget?
~ Rodney
Re: cancel browser widget navigation - possible?
I believe that rule is a way to help deal with bots and spam, since I see you now have 11 posts, that restriction should be lifted on your account, I think.
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: cancel browser widget navigation - possible?
Simply target your links to a new window (target="_blank").
Then the widget doesn't follow the link.
But if you run the same htmltext in an ordinary browser the link navigates away.
Then the widget doesn't follow the link.
But if you run the same htmltext in an ordinary browser the link navigates away.
shiftLock happens
Re: cancel browser widget navigation - possible?
This works for me. Replace the site URL with yours.
In the Browser widget;
on browserNavigateBegin pUrl
if "2108.co.uk" is not among the words of pUrl then
exit to top
end if
end browserNavigateBegin
In the Browser widget;
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
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
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: cancel browser widget navigation - possible?
Why?rodneyt wrote:Seems like not being able to detect/cancel/manage navigation in the browser widget is an issue that should be addressed ....
The widget is a "core" web engine. What you want is done by different browser flavours, that is in your app you have also to handle this by yourself. If LiveCode doesn't support this by widget messages you can still do that in JavaScript.
TMHO, adding all such navigation features (that require short javascript callback cycles) to the widget would make the widget slower.
shiftLock happens
Re: cancel browser widget navigation - possible?
Hi Andy,
This detects navigation away but exiting to top doesn't stop the navigation (at least not for me)
e.g.
on browserNavigateBegin pUrl
if not (pUrl contains "DOMAIN") then
answer "Navigating away to:" && pURL
exit to top
end if
... for me this shows answer dialog once pURL is already displayed.
This detects navigation away but exiting to top doesn't stop the navigation (at least not for me)
e.g.
on browserNavigateBegin pUrl
if not (pUrl contains "DOMAIN") then
answer "Navigating away to:" && pURL
exit to top
end if
... for me this shows answer dialog once pURL is already displayed.
Re: cancel browser widget navigation - possible?
Thanks for the suggestion. That is the default behaviour in my web app (I am already targeting _blank on my URLs):
This does not stop widget from following links (tested on OSX) If this is working for you can you provide a sample stack that illustrates?
This does not stop widget from following links (tested on OSX) If this is working for you can you provide a sample stack that illustrates?
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: cancel browser widget navigation - possible?
Make a new stack with a browser widget and a button.
This is the effect here:
The shiftKey-down-htmltext does nothing when the link is clicked
the shiftKey-up-htmltext navigates to the linked URL.
This works also in the sample stack "TextEditFull" I made using a browser widget.
There an inserted link is not allowed to navigate away from the editor.
This is the effect here:
The shiftKey-down-htmltext does nothing when the link is clicked
the shiftKey-up-htmltext navigates to the linked URL.
This works also in the sample stack "TextEditFull" I made using a browser widget.
There an inserted link is not allowed to navigate away from the editor.
Code: Select all
on mouseUp
if the shiftkey is down then
set htmltext of widget "browser" to \
"<html><body><a href='http://hyperhh.de' target='_blank'>Hi</a></body</html>"
else
set htmltext of widget "browser" to \
"<html><body><a href='http://hyperhh.de'>Hi</a></body</html>"
end if
end mouseUp
shiftLock happens
Re: cancel browser widget navigation - possible?
I suggest reading over thread http://runtime-revolution.278305.n4.nab ... 21826.html which sets out the issues quite well. I'm just asking for a way to be able to effectively cancel navigation away. For example, if "exit to top" within browserNavigateBegin actually worked to cancel navigation, that would be fine.
[-hh] wrote: ↑Tue Oct 23, 2018 9:10 pmWhy?rodneyt wrote:Seems like not being able to detect/cancel/manage navigation in the browser widget is an issue that should be addressed ....
The widget is a "core" web engine. What you want is done by different browser flavours, that is in your app you have also to handle this by yourself. If LiveCode doesn't support this by widget messages you can still do that in JavaScript.
...
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: cancel browser widget navigation - possible?
This will certainly work.
Code: Select all
on browserNavigateBegin pURL
-- you can't catch the htmltext here, this is already the new one
-- if pURL is not empty then set the URL of me to empty --> CANCELS (optionally)
set htmltext of me to myHTML --> whatever is YOUR current (saved) htmltext
end browserNavigateBegin
shiftLock happens
Re: cancel browser widget navigation - possible?
... but is not a viable option for me as I am working with a SPA (single page app) which dynamically changes content (eg as synchronous changes happen or as user scrolls window).
[-hh] wrote: ↑Tue Oct 23, 2018 10:40 pmThis will certainly work.
Code: Select all
on browserNavigateBegin pURL -- you can't catch the htmltext here, this is already the new one -- if pURL is not empty then set the URL of me to empty --> CANCELS (optionally) set htmltext of me to myHTML --> whatever is YOUR current (saved) htmltext end browserNavigateBegin