CallBackResponse not working all the times

<< Click to Display Table of Contents >>

Navigation:  Forum >

CallBackResponse not working all the times

Forum link

 


 

01-11-2020, 05:45 PM:

 

Please I need to execute some javascript commands in my project. I found that the CallBackResponse can do the job.

 

The issue I face is that the procedure is not working all the times.

 

The first example which i want to focus to a text box is working perfectly.

 

var

 

  js: string;

 

begin

 

  js := 'document.getElementById("TXTQUANTITY").focus();';

 

  WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);

 

end;

 

but when i try to run other commands it does nothing even a simple pop message

 

  js:=  'windows.alert("I am an alert box!");';

 

  WebApplication.CallBackResponse.AddJavaScriptToExecute(js);

 

Is there something else I have to pay attention.

 

i am running XE6 and Intraweb 14.0.50 version

 


 

01-12-2020, 12:15 AM:

 

The syntax is incorrect in the second example. The object is window (singular), not windows. You can omit window object and use alert() only too.

 


 

01-17-2020, 06:23 AM:

 

(01-12-2020, 12:15 AM)Alexandre Machado Wrote: [ -> ]The syntax is incorrect in the second example. The object is window (singular), not windows. You can omit window object and use alert() only too.

 

I tried with alert only. It is not working. The problem is not in the syntax (it was a mistake when I wrote this post).

 


 

01-20-2020, 01:51 AM:

 

This is the standard way of producing that output. You say that it is not working at "all times". What does it mean? Does it work sometimes? Have you checked the console log window for other JavaScript errors?

 

This version is also ancient (probably 7+ years old). I strongly recommend you to update it to a newer release.

 


 

02-15-2020, 07:37 AM:

 

I have a TIWAppForm with an TIWLabel (TXTWIDTH) that is updated with the following code:

 

procedure TIndex.cmdLoginAsyncMouseOver(Sender: TObject; EventParams: TStringList);

 

var

 

js: string;

 

begin

 

js:='document.getElementById("TXTWIDTH").innerHTML = screen.width;';

 

WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);

 

end;

 

How can I get the value of TXTWIDTH label?

 


 

02-18-2020, 09:25 AM:

 

What are you trying to accomplish? The browser window dimensions are already set in WebApplication.FormWidth and FormHeight.

 

If you want to keep track if it when browser resizes, set an OnAsyncResize event handler and the information will be updated every time the browser resizes.

 


 

02-23-2020, 06:07 AM:

 

(02-18-2020, 09:25 AM)Alexandre Machado Wrote: [ -> ]What are you trying to accomplish? The browser window dimensions are already set in WebApplication.FormWidth and FormHeight.

 

If you want to keep track if it when browser resizes, set an OnAsyncResize event handler and the information will be updated every time the browser resizes.

 

Unfortunately, I have already tried this and for sure it doesn't work. FormWidth and FormHeight cannot return the correct dimensions when it runs from a mobile browser like Samsung Internet.  Anyway I found somewhere else the following solution:

 

procedure TIndex.IWAppFormCreate(Sender: TObject);

 

const

 

  jsTag = '<script language="javascript" type="text/javascript">%s</script>';

 

var

 

  AjaxFunc: string;

 

begin

 

  AjaxFunc := 'function myAjaxFunc() {' + #13 +

 

      'executeAjaxEvent("&data="+screen.width, null,"' + UpperCase(Self.Name) +

 

      '.DoMyAjaxFunc", false, null, true);' + #13 +

 

      'return true;}';

 

  PageContext.ExtraHeader.Add(Format(jsTag, [AjaxFunc]));

 

  WebApplication.RegisterCallBack(UpperCase(Self.Name) + '.DoMyAjaxFunc', DoMyAjaxFunc);

 

  cmdLogin.ScriptEvents.HookEvent('OnMouseOver', 'myAjaxFunc();');

 

end;

 

procedure TIndex.DoMyAjaxFunc(EventParams: TStringList);

 

var

 

  sl: TStrings;

 

  s: string;

 

begin

 

  sl := TStringList.Create;

 

  try

 

    sl.StrictDelimiter := True;

 

    sl.CommaText := EventParams.Values['data'];

 

    s := sl.CommaText;

 

  finally

 

    sl.Free;

 

  end;

 

  UserSession.MyBrowserWidth:=s2i(s);

 

end;

 


 

02-23-2020, 10:44 AM:

 

Still not sure what you want to accomplish but I suggest that you read about the difference between screen.width and window.innerWidth which are *very* different:

 

https://stackoverflow.com/questions/3744...reen-width

 

For must purposes, screen.width is irrelevant because does not correspond to the dimension available to the form

 


 

02-26-2020, 06:21 AM:

 

I just want to identify the dimensions of the browser in order to adjust my components. For any browser. Desktop and Mobile. I tried also with innerWidth. It doesn't return exact result. Only the screen.width works.