postbacked links and buttons href="javascript:"

22 views
Skip to first unread message

Franklin Brauning

unread,
Dec 29, 2016, 10:46:24 AM12/29/16
to Nitrogen Project / The Nitrogen Web Framework for Erlang
Is it feasible to change that "javascript:" href, with some standard url, so an user can
load that link in another tab, or even "download link" ?

What would I set instead of "javascript:"?  The url of the current module but
with some parameters so the page loads itself in a "static" fashion instead of waiting for events.

That would bring some more abstractions to the table but the point is to make sites
more usable to power users who tend to spawn several tabs from a page (just like when
one is reading a wiki page...)



Jesse Gumm

unread,
Jan 4, 2017, 2:46:01 PM1/4/17
to nitrogenweb
Hi Franklin,

You can indeed change the url in a link that has a postback.  It middle-clicking it will then just follow the URL rather than issuing a postback.

It's hard to say what to set it to without knowing the context.  If the postback is just doing a simple redirect, then obviously setting the URL to the redirect path would be simplest.

If, however, you're doing something more complicated and wrapping up some contents to be processed in some way, then I'd wrap those contents with wf:pickle, stick that pickled value on the query-string line, and then on the receiving end, retrieve that value from the query string (wf:q(my_pickled_values)), process those values accordingly and proceed.

Does that make any sense?

-Jesse

--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb+unsubscribe@googlegroups.com.
To post to this group, send email to nitro...@googlegroups.com.
Visit this group at https://groups.google.com/group/nitrogenweb.
For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Franklin Brauning

unread,
Jan 4, 2017, 3:25:05 PM1/4/17
to Nitrogen Project / The Nitrogen Web Framework for Erlang
I've tried this just when I posted it and it didn't work, because the postbacked link overrides the url= parameter to
"javscript:". More precise, the #link.url's default is "javascript:". I changed that in the wf:hrl to "http://goo.com" (for example)
and it worked but now the postback semantic were lost.




On Wednesday, January 4, 2017 at 4:46:01 PM UTC-3, Jesse Gumm wrote:
Hi Franklin,

You can indeed change the url in a link that has a postback.  It middle-clicking it will then just follow the URL rather than issuing a postback.

It's hard to say what to set it to without knowing the context.  If the postback is just doing a simple redirect, then obviously setting the URL to the redirect path would be simplest.

If, however, you're doing something more complicated and wrapping up some contents to be processed in some way, then I'd wrap those contents with wf:pickle, stick that pickled value on the query-string line, and then on the receiving end, retrieve that value from the query string (wf:q(my_pickled_values)), process those values accordingly and proceed.

Does that make any sense?

-Jesse
On Thu, Dec 29, 2016 at 9:46 AM, Franklin Brauning <braun...@gmail.com> wrote:
Is it feasible to change that "javascript:" href, with some standard url, so an user can
load that link in another tab, or even "download link" ?

What would I set instead of "javascript:"?  The url of the current module but
with some parameters so the page loads itself in a "static" fashion instead of waiting for events.

That would bring some more abstractions to the table but the point is to make sites
more usable to power users who tend to spawn several tabs from a page (just like when
one is reading a wiki page...)



--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb...@googlegroups.com.

To post to this group, send email to nitro...@googlegroups.com.
Visit this group at https://groups.google.com/group/nitrogenweb.
For more options, visit https://groups.google.com/d/optout.

Jesse Gumm

unread,
Jan 4, 2017, 3:45:03 PM1/4/17
to nitrogenweb
Hmm.

The postback definitely does not override the url provided.

As a simple example, I just whipped up this:

 body() ->
      [
          #link{text="click me", postback=do, url="http://google.com"}
      ].
  
 event(do) ->
      wf:wire(#alert{text="clicked"}).

If you left-click the link, it issues the postback, but does not redirect.
If you middle-click the link, it redirects, and does not do the postback.

Are you trying to accomplish something differently?  I would say if you want a link to redirect, I wouldn't even do the postback, since you're reproducing work anyway (processing something before a redirect), and would instead just use wf:pickle to wrap up the data and pass it along on the querystring.

-Jesse



To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb+unsubscribe@googlegroups.com.

To post to this group, send email to nitro...@googlegroups.com.
Visit this group at https://groups.google.com/group/nitrogenweb.
For more options, visit https://groups.google.com/d/optout.

Franklin Brauning

unread,
Jan 5, 2017, 12:53:56 PM1/5/17
to Nitrogen Project / The Nitrogen Web Framework for Erlang
Weird... clicking it I'm getting, the postback and also the redict to the url,

In pseudo code:
  #link { url="http://www.google.com", postback=clicked }

  event(clicked) ->
     ?PRINT(clicked),    <-- it does log
     wf:redirect("http://www.yahoo.com")    <-- doesnt work, already lost all control of the client
     ?PRINT(tried_yahoo_but_doesnt_work)    <--- it does log too

You know, this kind of situations could be added to FAQ:
  -  What happens if I have a button with url and postback?
  - Why wf:flush() is not working? ...becasue it's only valid in comet context...
  - wf:q(...) is not working!  ... maybe you're doing it in comet context...
  - can I wf:q(...) inside a #custom validator?  yes .
Reply all
Reply to author
Forward
0 new messages