picyka Posted October 26, 2021 Share Posted October 26, 2021 btnLinkAtendimento.JSInterface.JSAddListener('tap', 'function(sender, e, eOpts){window.open("https://api.whatsapp.com/send?phone=55' + lTelefone + '&text='+lTexto+'", "_blank")}'); Good morning, I currently run a call on the client side like this, I would like that, before triggering the tap, I could execute the click on the server side, would that be possible? Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted October 26, 2021 Share Posted October 26, 2021 31 minutes ago, picyka said: btnLinkAtendimento.JSInterface.JSAddListener('tap', 'function(sender, e, eOpts){window.open("https://api.whatsapp.com/send?phone=55' + lTelefone + '&text='+lTexto+'", "_blank")}'); Good morning, I currently run a call on the client side like this, I would like that, before triggering the tap, I could execute the click on the server side, would that be possible? Hello Do you want to call window.open from serverside or just send an ajaxevent to server? Quote Link to comment Share on other sites More sharing options...
picyka Posted October 26, 2021 Author Share Posted October 26, 2021 1 minuto atrás, Hayri ASLAN disse: Olá Você deseja ligar para o window.open do serverside ou apenas enviar um evento ajaxevent para o servidor? I wanted that, before executing the method on the client, I would be able to execute any server. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted October 26, 2021 Share Posted October 26, 2021 Hi, As Hayri asked you, you have to pass the request to the server (ajaxRequest) and from there it is up to you to decide what you need to do (UniSession.AddJS for example). Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted October 26, 2021 Share Posted October 26, 2021 1 hour ago, picyka said: I wanted that, before executing the method on the client, I would be able to execute any server. procedure TMainmForm.UnimButton1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName='customTap' then begin UniSession.AddJS('window.open("https://api.whatsapp.com/send?phone=55123456", "_blank");') end; end; procedure TMainmForm.UnimFormCreate(Sender: TObject); begin with UnimButton1, JSInterface do begin JSAddListener('tap', JSFunction('ajaxRequest('+JSName+', "customTap")')) end; end; Quote Link to comment Share on other sites More sharing options...
picyka Posted October 26, 2021 Author Share Posted October 26, 2021 9 minutes ago, Sherzod said: Hi, As Hayri asked you, you have to pass the request to the server (ajaxRequest) and from there it is up to you to decide what you need to do (UniSession.AddJS for example). I'll try it here, thanks Quote Link to comment Share on other sites More sharing options...
picyka Posted October 26, 2021 Author Share Posted October 26, 2021 13 minutes ago, Hayri ASLAN said: procedure TMainmForm.UnimButton1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName='customTap' then begin UniSession.AddJS('window.open("https://api.whatsapp.com/send?phone=55123456", "_blank");') end; end; procedure TMainmForm.UnimFormCreate(Sender: TObject); begin with UnimButton1, JSInterface do begin JSAddListener('tap', JSFunction('ajaxRequest('+JSName+', "customTap")')) end; end; It almost worked, when you're on your cell phone, this method below doesn't work... UniSession.AddJS('window.open("https://api.whatsapp.com/send?phone=55' + lTelefone + '&text='+lTexto+'", "_blank");'); from the desktop, it works. Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted October 26, 2021 Share Posted October 26, 2021 25 minutes ago, picyka said: It almost worked, when you're on your cell phone, this method below doesn't work... UniSession.AddJS('window.open("https://api.whatsapp.com/send?phone=55' + lTelefone + '&text='+lTexto+'", "_blank");'); from the desktop, it works. As window.open opens a new tab, you're calling window.open indirectly (from server side), not in direct response to a user event(tap event). Most browsers will block those calls. You should do your check inside tap event or you should use sync ajaxrequest. Please refer below post for Sync ajaxrequest. Quote Link to comment Share on other sites More sharing options...
picyka Posted October 26, 2021 Author Share Posted October 26, 2021 49 minutes ago, Hayri ASLAN said: À medida que o window.open abre uma nova guia, você está chamando window.open indiretamente (do lado do servidor), não em resposta direta a um evento do usuário (toque no evento). A maioria dos navegadores bloqueará essas chamadas. Você deve fazer o seu check dentro do evento de toque ou você deve usar o ajaxrequest sincronizado. Por favor, consulte abaixo o post para Sync ajaxrequest. with btnLinkAtendimento, JSInterface do JSInterface.JSAddListener('tap', JSFunction('ajaxRequest('+JSName+', "customTap",[],false).responseText == ''true''')); perfect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.