1. wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by DanM Jan 07, 2009
- 1048 views
- Last edited Jan 08, 2009
I should preface this question with a demur:
I am NOT trying to build any kind of web "spoof" page, and if that possibility seems too onerous to reply to publicly, then please consider replying directly, to:
euph2005-eudan (atNoSpam) yahoo.com
My question is, in wxEuphoria, using the html window control, is there some way I can intercept a users click on a text link, so program logic can decide what to actually do with the click action, rather than immediately causing a browser to jump to the clicked link?
Dan
2. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by DanM Jan 08, 2009
- 1019 views
Never mind, I finally looked at the demo, & it's obvious, sigh.
Dan
3. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by DanM Jan 08, 2009
- 979 views
Sigh, I spoke too soon. It may be obvious, but it doesn't work.
In the html example, the following code does not actually execute, though it appears to:
procedure on_link_clicked( atom html_win, sequence href, sequence target ) load_html_page( html, href ) return end procedure set_link_event( html, routine_id("on_link_clicked") )
That is, if I comment out the "load_html_page" line, it still DOES jump to whatever link is clicked on, and if I put a status bar message output in that procedure, the message doesn't display; those two together tell me that the event handler isn't actually functioning, something else is, and it's the something else that I want to intercept or prevent from occurring, so I can use the clicking on a "link" make something else occur instead.
So, any ideas how I can actually intercept a clicked link?
Dan
4. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by ghaberek (admin) Jan 08, 2009
- 1016 views
It doesn't work... I'm working on it... it seems slightly beyond my current C knowledge.
-Greg
5. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by ghaberek (admin) Jan 09, 2009
- 1030 views
Okay, I got it now...
From wxHtmlWindow docs:
[quote=wxWidgets] Called when user clicks on hypertext link. Default behaviour is to emit a wxHtmlLinkEvent and, if the event was not processed or skipped, call LoadPage and do nothing else. Overloading this method is deprecated; intercept the event instead. [/quote]
So we must do this instead:
procedure on_link_click( atom this, atom event_type, atom id, atom event ) atom link sequence href, target link = get_link_event_info( event ) -- wxHtmlLinkInfo object href = get_link_href( link ) -- clicked url href target = get_link_target( link ) -- target frame, unused -- if the event was not processed or skipped, -- call load_html_page and do nothing else load_html_page( html, href ) end procedure set_event_handler( html, get_id(html), wxEVT_COMMAND_HTML_LINK_CLICKED, routine_id("on_link_click") )
I had to update wxEuphoria to support this. I've made some other addtions/revisions as well. I'll try to push out a new version ASAP. I guess one release per month wouldn't be too bad...
-Greg
6. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by DanM Jan 09, 2009
- 1025 views
Okay, I got it now...
From wxHtmlWindow docs:
[quote=wxWidgets] Called when user clicks on hypertext link. Default behaviour is to emit a wxHtmlLinkEvent and, if the event was not processed or skipped, call LoadPage and do nothing else. Overloading this method is deprecated; intercept the event instead. [/quote]
So we must do this instead:
procedure on_link_click( atom this, atom event_type, atom id, atom event ) atom link sequence href, target link = get_link_event_info( event ) -- wxHtmlLinkInfo object href = get_link_href( link ) -- clicked url href target = get_link_target( link ) -- target frame, unused -- if the event was not processed or skipped, -- call load_html_page and do nothing else load_html_page( html, href ) end procedure set_event_handler( html, get_id(html), wxEVT_COMMAND_HTML_LINK_CLICKED, routine_id("on_link_click") )
I had to update wxEuphoria to support this. I've made some other addtions/revisions as well. I'll try to push out a new version ASAP. I guess one release per month wouldn't be too bad...
-Greg
Very good! And thanks a lot! But I gotta ask:
it looks to me that what you've done is to make sure that the event handler
properly handles a click on a link, whereas previously the handler was being
ignored (?), but was nonetheless jumping to the link?
Now, the fix you've made, will that allow, if the jumping to the link stuff is deliberately
not included in the event handler, that something else can programmatically be caused to
occur on clicking on a link?? That's what I'm wanting to be able to do. Maybe
I'm not understanding the action correctly?
(What I mean is, since the jumping to the link DID occur before, even though the
event handler wasn't what was making that happen, will that jump still happen
if I try to intercept the action from within the event handler, with alternative
code? I want the alternative code to act, not the "accidental" jump.)
Dan
7. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by ghaberek (admin) Jan 09, 2009
- 967 views
Very good! And thanks a lot! But I gotta ask:
it looks to me that what you've done is to make sure that the event handler
properly handles a click on a link, whereas previously the handler was being
ignored (?), but was nonetheless jumping to the link?
Now, the fix you've made, will that allow, if the jumping to the link stuff is deliberately
not included in the event handler, that something else can programmatically be caused to
occur on clicking on a link?? That's what I'm wanting to be able to do. Maybe
I'm not understanding the action correctly?
(What I mean is, since the jumping to the link DID occur before, even though the
event handler wasn't what was making that happen, will that jump still happen
if I try to intercept the action from within the event handler, with alternative
code? I want the alternative code to act, not the "accidental" jump.)
I'm afraid I don't quite get what you're saying. Let me explain the three possible scenarios:
- You handle the event, fetch the href, and pass it to load_html_page. (As my example demonstrates).
The wxHtmlWindow operates correctly. - You handle the event, but do not call load_html_page.
Nothing will happen when the user clicks a link. - You do not handle the event.
The wxHtmlWindow operates correctly.
Your event handler may perform any other action to react to the link. The main point is calling load_html_page to allow the link to pass, and not calling it to have it do nothing.
-Greg
8. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by DanM Jan 09, 2009
- 996 views
Greg,
I'm not really sure how clear my question was, to anyone but myself, so I'll ask it another way.
Suppose I were to create an html page with a bunch of "dummy" links, ie, "link1.htm", "link2.htm", etc, and then load it into the wxEuphoria html window.
What I'm looking to do is allow clicking on those dummy links to be as if the text associated with the links were in fact buttons, such that clicking on them would then be trapped in the event handler and then cause various different actions, as if the words were in fact a bunch of buttons.
Dunno if that's any clearer?
Dan
9. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by DanM Jan 09, 2009
- 1002 views
ok, looks like it will do exactly what I want, disregard my immediately previous post
Dan
10. Re: wxEuphoria: how can I INTERCEPT html link clicks?
- Posted by ghaberek (admin) Jan 09, 2009
- 970 views
I'm not really sure how clear my question was, to anyone but myself, so I'll ask it another way.
Suppose I were to create an html page with a bunch of "dummy" links, ie, "link1.htm", "link2.htm", etc, and then load it into the wxEuphoria html window.
What I'm looking to do is allow clicking on those dummy links to be as if the text associated with the links were in fact buttons, such that clicking on them would then be trapped in the event handler and then cause various different actions, as if the words were in fact a bunch of buttons.
Dunno if that's any clearer?
ok, looks like it will do exactly what I want, disregard my immediately previous post
I understand what you're getting at now. Yes, that should work fine. In fact, that is how you could duplicate a "frames" layout with multiple wxHtmlWindows. When the user clicks a link in one window, load it into the other.
-Greg