Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CallBackResponse not working all the times
#1
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
Reply
#2
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.
Reply
#3
(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).
Reply
#4
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.
Reply
#5
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?
Reply
#6
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.
Reply
#7
(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;
Reply
#8
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
Reply
#9
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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)