andyhill Posted July 14, 2021 Share Posted July 14, 2021 I have MainModule BeforeLogin code decoding the URL parameters and setting appropriate flags - all good. After acting on these flags in the MainForm I want to remove the parameters from the Browser URL Address Bar without reloading the page, my code below while executing does not achieve that result, please advise how - Thanks. eg. https://myDomain.com/?doSomething=log --> https://myDomain.com procedure TMainForm.UniFormShow(Sender: TObject); begin if FirstTimeFlag = True then begin FirstTimeFlag:= False; if UniMainModule.RequestEmailLog = True then begin UniMainModule.RequestEmailLog:= False; MainForm.ShowMask(); UniServerModule.EmailLog(EmailAddress); MainForm.HideMask; UniSession.AddJS('var newurl = MainForm.window.location.protocol + "//" + MainForm.window.location.host + MainForm.window.location.pathname; '+ 'MainForm.window.history.pushState({path: newurl}, '', newurl); '); end; end; end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 15, 2021 Share Posted July 15, 2021 7 hours ago, andyhill said: eg. https://myDomain.com/?doSomething=log --> https://myDomain.com Hello, In the beginning, how do you type a link, manually or via a link? Quote Link to comment Share on other sites More sharing options...
andyhill Posted July 15, 2021 Author Share Posted July 15, 2021 I can use the URL https://myDomain.com/?doSomething=log or add the parameters to the landing page https://myDomain.com /?doSomething=log Quote Link to comment Share on other sites More sharing options...
Erik Posted July 15, 2021 Share Posted July 15, 2021 I want to do the same ;-) Simply delete the post parameter does not result in new url. In my case: You can start the loginscreen with some parameters. After login I want to show the mainform without the login options parameters in the url Quote Link to comment Share on other sites More sharing options...
irigsoft Posted July 15, 2021 Share Posted July 15, 2021 Hello, try this. https://www.30secondsofcode.org/articles/s/javascript-modify-url-without-reload procedure TMainForm.UniFormActivate(Sender: TObject); var EnableAutoLog : Boolean; begin If (TRIM (TUniGUISession(UniSession).UniApplication.Parameters.Values ['login']) <> '') and (EnableAutoLog) then begin //replace URL UniSession.AddJS( // Current URL: UniSession.ARequest.Referer 'const nextURL = ''' + StringReplace (UniSession.ARequest.Referer,'login=' + TUniGUISession(UniSession).UniApplication.Parameters.Values ['login'],'',[rfReplaceAll,rfIgnoreCase]) + ''';' + 'const nextTitle = ''' + UniServerModule.Title + ''';' + 'const nextState = { additionalInformation: ''Updated the URL with JS'' };' // This will create a new entry in the browser's history, without reloading + 'window.history.pushState(nextState, nextTitle, nextURL);' // This will replace the current entry in the browser's history, without reloading + 'window.history.replaceState(nextState, nextTitle, nextURL);' ); end; But, You must know this will replace only URL, on Google Console will be seen all history as clear text !!! Quote Link to comment Share on other sites More sharing options...
irigsoft Posted July 15, 2021 Share Posted July 15, 2021 3 hours ago, Erik said: After login I want to show the mainform without the login options parameters in the url If You made this by security reason, this is not real secure method. For more info check here: Quote Link to comment Share on other sites More sharing options...
andyhill Posted July 15, 2021 Author Share Posted July 15, 2021 The suggestion to use UniSession.ARequest.Referer fails as it is blank. My original code is fine and it was only missing the window.history.replaceState call. // UniSession.AddJS('const nextURL = window.location.protocol + "//" + window.location.host + window.location.pathname; '+ 'const nextTitle = ''' + UniServerModule.Title + '''; '+ 'const nextState = {additionalInformation: ''Updated the URL with JS'' }; '+ 'window.history.pushState(nextState, nextTitle, nextURL); '+ 'window.history.replaceState(nextState, nextTitle, nextURL); '); // Thank you 1 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.