Jump to content

Changing browser/window URL from UniGUI


wprins

Recommended Posts

I've set up processing to to look for and capture parameters passed via the URL (e.g. GET parameters, captured in MainModule.BeforeLogin, then deal with login/auth etc, and then used later etc.) 

 

However, the URL parameters stay on the browser address.  I'd like to remove them after capture but I'm not sure how to get this effect in the browser.  I assume I'd have to inject some JS at some suitable point (perhaps using UniSession.AddJS()?)

 

 

With plain javascript one could do e.g. 

<html>
    <head>
    </head>
    <body>
        <div id="urldiv"></div>
        <script type="application/javascript">
            var urldiv = document.getElementById('urldiv');
            urldiv.innerHTML = '<p>Page opened with: '+window.location+'</p>';
            window.history.replaceState({} , '', window.location.origin + window.location.pathname );
            urldiv.innerHTML = urldiv.innerHTML + '<p>Location changed to: '+window.location+'</p>'
        </script>
    </body>
</html>

Opening this page with e.g. ?foo=bar will result in the query params being removed from the URL in the browser without a page reload.

 

(I have a feeling this ought to be possible without too much fuss, and have hunted around the demos and so on to try and find an example, and have also some small amount of time inspecting e.g. UniSession but it's not been obvious what to do where, apologies if I've missed the obvious.)

 

 

Link to comment
Share on other sites

Is it maybe possible that you can try to pass the parameters in the header instead of in the URL? Then they wont be visible in the first place.

 

In general it would be beter yes (actually having them in the body (POST) be better still perhaps IMHO).  But UniGUI seems to use GET for the client side event propagation for whatever reason (instead of POST).  

 

Also in my particular case I don't have the luxury of passing parameters any way other than via URL.  (It is a green screen application displaying the URL, with the terminal emulator being able to recognize a URL and launch the browser from it.  Using headers or POST in this context would unfortunately require more smarts from a piece of software I don't control.)

 

Thanks for the comment though, in the more general case I would be very much interested to know how to pass them via header or via POST (if possible.)

Link to comment
Share on other sites

  • 4 weeks later...

Any REST client should give you the ability to add header values.

 

Here is an example where I read one of the header values in TUniServerModule.

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo;
  AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean);
var
  dm : TdmReportData;

begin
  if ARequestInfo.URI='/report/finsummary' then
  begin
    dm := TdmReportData.Create(nil);
    try
      dm.qryReport.Connection := dm.FDConnection;
      AResponseInfo.ContentText := dm.GenerateReportPDF(repFinSummary, '') + ' header [user] = ' + ARequestInfo.RawHeaders.Values['user'];
      AResponseInfo.ResponseNo := 200;
      AResponseInfo.WriteContent;
      Handled := True;
    finally
      dm.Free;
    end;
 end;
end;
Link to comment
Share on other sites

i dont know if it helps - but:

 

i use a index.php file fpr my uniGui-App  ( a iframe loads the unigui) .. so the adress in the browser is www.mydomain.com   

 

if i want to send parameters - i send the parameters to  www.mydomain.com/unigui.dll?value=something (a new instance of unigui will start..)

 

if the unigui.dll becomes parameters, this instance of unigui search the allready running session of the user - and sends the value to the open session and closes itselfe ...


begin
    // Suche Session und starte Suche
        ASessionList := UniServerModule.SessionManager.Sessions.SessionList; //  .SessionList.  ist;//  .LockList;
          try
            for I := 0 to ASessionList.Count -1 do
            begin
              USession := TUniGUISession(ASessionList[i]);
              M := USession.UniMainModule as TUniMainModule;
                 if UniApplication.UniSession.SessionID <> USession.SessionId  then   // Do not close my OWN Session
                 begin
                    if M.benutzernummer = handy_user_id then
                    begin
                          M.syn_user   :=handy_syn_user;
                          M.syn_layer  :=handy_layer;
                          M.syn_nummer :=handy_nummer;         // send parameters to the user session
                          M.syn_name   :=handy_name;
                          M.syn_art    :=handy_art;


                    end;
                 end;
             end;
          finally
             uniapplication.terminate;   // ... and close the not needed session;
          end;
end;



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...