NetTalk Central

Author Topic: JavaScript to select HTML page from HTML button link  (Read 2382 times)

springguy

  • Full Member
  • ***
  • Posts: 195
    • View Profile
    • Email
JavaScript to select HTML page from HTML button link
« on: April 11, 2012, 03:24:01 AM »
I have an HTML page with embedded NetTalk components.  On the HTML page, I have an HTML button with a link to another HTML page.  What I would like to do is to allow that link to be dynamically selected based on NetTalk session values.  In other words, based on a GSV variable, to link to one of some number of links.

I assume this will require some JavaScript added to the HTML page, but how would it have access to the NetTalk session variables?

Thoughts?
Mike Springer

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: JavaScript to select HTML page from HTML button link
« Reply #1 on: April 11, 2012, 04:08:03 AM »
at what point do you know what the URL should be? When the page is displayed to the user?
Or at some point afterwards, when the user has been interacting with the page for a while?

cheers
Bruce

springguy

  • Full Member
  • ***
  • Posts: 195
    • View Profile
    • Email
Re: JavaScript to select HTML page from HTML button link
« Reply #2 on: April 11, 2012, 04:59:20 AM »
Bruce,
Programatically, I would know the potential URLs when the page is displayed.  But, I don't know which one is the appropriate one without looking at a session value, then upon testing the session value, I would select which URL would be the right one to call.

Mike

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: JavaScript to select HTML page from HTML button link
« Reply #3 on: April 11, 2012, 10:03:09 PM »
there are two approaches you can take here.

a) have the URL pre-prepared in a SessionValue. Then use the session value on the web page. For example;

<a href="<!-- Net:s:url -->">whatever</a>

This method is very clean, but pre-supposes you can have the URL session value preloaded.

Another approach is to create a NetWebSource procedure that just returns the value. The key here is to be careful that it doesn't return anything else, so you need to inspect the source for a netwebsource, and make sure it only returns the URL. Then, assuming the procedure is called say fred, your html looks like this;

<a href="<!-- Net:fred -->">whatever</a>

Cheers
Bruce

springguy

  • Full Member
  • ***
  • Posts: 195
    • View Profile
    • Email
Re: JavaScript to select HTML page from HTML button link
« Reply #4 on: April 27, 2012, 07:01:25 AM »
Bruce,
I am particularly interested in using the netwebsource approach you mentioned.  What I don't understand is how the return from the netwebsource works to direct the call to the desired url.

In other words, in the static page link I have:

<a href="!<-- Net:MyWebSource -->">Click Here to Go To The Right Place</a>

In MyWebSource procedure, I have the following code:

If p_web.GSV('MyDirectingVariable') = 'Y'
    ! I want to specify the url that is appropriate here
Else
    ! I want to specify some other url here
End

Your previous post simply said the source procedure returns the desired URL, but I don't understand (as you can see in my example above) how you return the url to call the desired page.

Mike

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: JavaScript to select HTML page from HTML button link
« Reply #5 on: April 27, 2012, 08:45:45 PM »
If p_web.GSV('MyDirectingVariable') = 'Y'
    ! I want to specify the url that is appropriate here
   packet = 'http://www.capesoft.com'
Else
    ! I want to specify some other url here
   packet = 'http://www.clarionshop.com'
End
do SendPacket

springguy

  • Full Member
  • ***
  • Posts: 195
    • View Profile
    • Email
Re: JavaScript to select HTML page from HTML button link
« Reply #6 on: April 28, 2012, 10:23:58 AM »
Thanks Bruce - worked perfectly!
Mike