Get return value form js function in SB [solved]

Just starting out? Need help? Post your questions and find answers here.
menschmarkus
Posts: 54
Joined: Thu Apr 10, 2014 3:35 pm

Get return value form js function in SB [solved]

Post by menschmarkus »

Hi @ all

I try to readout set cookies by SB. Unfortunately there is no explicit SB function existing or lets say I did not find it.
It is no problem doing it by calling a php script but I would like to read it out directly without internet traffic.

However, I tried following

Code: Select all

Procedure js_cookies(mode.i,cname.s)
  Select mode         ;Read cookies
    Case 0
      !function getCookie(cname){
      ! let name = cname + "=";
      ! let decodedCookie = decodeURIComponent(document.cookie);
      ! let ca = decodedCookie.split(';');
      ! for(let i = 0; i <ca.length; i++) {;
      !   while (c.charAt(0) == ' ') {
      !     c = c.substring(1);
      !   }
      !   if (c.indexOf(name) == 0) {
      !     return c.substring(name.length,c.length);
      !   }
      ! }
      ! return "";
      !}    
      ProcedureReturn !getCookie(cname)								;<<-- does not work
  EndSelect
  
  js_cookies(0,"cookiename")
  
  ;JS code from W3Schools.com !
EndProcedure
So how can I set js function call variables and how can I get returned result?

Thanks for useful hints.

[edit:]
additionally information. I found some code here viewtopic.php?t=1361 but as soon I run app with enabled procedure, no more window appears. It is not necessary to call procedure for this effect happens. As soon I make a block comment to the procedure app works fine. With above shown code this effect is not appearing.
Last edited by menschmarkus on Tue Jun 04, 2024 11:29 am, edited 1 time in total.
as soon you do it right, it works !
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Get return value form js function in SB

Post by Peter »

take a look at this functions:
viewtopic.php?p=5611#p5611

More comfortable than cookies: Preferences
https://github.com/spiderbytes/Preferences
menschmarkus
Posts: 54
Joined: Thu Apr 10, 2014 3:35 pm

Re: Get return value form js function in SB

Post by menschmarkus »

nice, that works

Thank you Peter
as soon you do it right, it works !
Post Reply