![]() |
CallBackResponse not working all the times - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: CallBackResponse not working all the times (/thread-1482.html) |
CallBackResponse not working all the times - promi8eas - 01-11-2020 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 RE: CallBackResponse not working all the times - Alexandre Machado - 01-12-2020 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. RE: CallBackResponse not working all the times - promi8eas - 01-17-2020 (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). RE: CallBackResponse not working all the times - Alexandre Machado - 01-20-2020 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. RE: CallBackResponse not working all the times - promi8eas - 02-15-2020 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? RE: CallBackResponse not working all the times - Alexandre Machado - 02-18-2020 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. RE: CallBackResponse not working all the times - promi8eas - 02-23-2020 (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. 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; RE: CallBackResponse not working all the times - Alexandre Machado - 02-23-2020 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/37443482/what-is-the-difference-between-window-innerwidth-and-screen-width For must purposes, screen.width is irrelevant because does not correspond to the dimension available to the form RE: CallBackResponse not working all the times - promi8eas - 02-26-2020 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. |