clement Posted December 14, 2016 Share Posted December 14, 2016 Hi, 1) How can I hide the parameter shown in the address bar? UniSession.AddJs('window.open(http://localhost:8077/?UserName=myName);'); Thank You. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 14, 2016 Share Posted December 14, 2016 Hi, For now can you try this... ?!: procedure TMainForm.UniButton1Click(Sender: TObject); begin UniSession.AddJS( 'var f = document.createElement("form"); '+ 'f.action="http://localhost:8077/"; '+ // the second app url 'f.method="POST"; f.setAttribute("target", "view");'+ 'var i=document.createElement("input"); '+ // Param1 'i.type="hidden"; '+ 'i.name="param1"; '+ 'i.value="Test"; '+ 'f.appendChild(i); '+ {'var i=document.createElement("input"); '+ // Param2 'i.type="hidden"; '+ 'i.name="param2"; '+ 'i.value="Test"; '+ 'f.appendChild(i); '+} 'document.body.appendChild(f); '+ 'window.open("", "view"); f.submit(); ' ); end; ... and use, you may need to disable "popup blocker": procedure TMainForm.UniFormShow(Sender: TObject); begin Caption := UniApplication.Parameters.Values['param1']; end; Best regards. Quote Link to comment Share on other sites More sharing options...
clement Posted December 14, 2016 Author Share Posted December 14, 2016 Thanks Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 In the above JS code, how do I display the URL in the same tab? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 9, 2021 Share Posted December 9, 2021 11 minutes ago, Frederick said: In the above JS code, how do I display the URL in the same tab? Hello, Please explain in more detail. Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 Please see attached video and testcase. When I click the button, I want the Google web site to be displayed in the same tab as my application. This should allow me to click the Back button from the Google page to return to my application. jssamepage.mp4 jssamepage.7z Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 18 minutes ago, Frederick said: Please see attached video and testcase. When I click the button, I want the Google web site to be displayed in the same tab as my application. This should allow me to click the Back button from the Google page to return to my application. jssamepage.mp4 jssamepage.7z 5.05 MB · 0 downloads If You try with replace this: 'window.open("", "view"); f.submit(); ' with this: 'window.open("www.youraddress.com","_self"); f.submit();' or this: 'window.open("?","_self"); f.submit();' more info: https://www.google.com/search?q=window.open+in+same+tab+jquery&oq=window.open+same+tab&aqs=chrome.2.0i19j0i19i22i30l4.7006j0j4&sourceid=chrome&ie=UTF-8 Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 14 minutes ago, irigsoft said: with this: 'window.open("www.youraddress.com","_self"); f.submit();' or this: 'window.open("?","_self"); f.submit();' Unfortunately, both options do not provide the intended result. The first one, 'window.open("https://www.google.com","_self"); f.submit();' , displays Google's web page in the same tab as the application AND displays the new URL in a new tab. The second option, 'window.open("?","_self"); f.submit();', relaunches my application in the same tab. This situation is unique because the JS code that Sherzod provided calls a URL and passes parameters to it. The examples provided in the above search link do not show how this can be done. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 3 minutes ago, Frederick said: Unfortunately, both options do not provide the intended result. The first one, 'window.open("https://www.google.com","_self"); f.submit();' , displays Google's web page in the same tab as the application AND displays the new URL in a new tab. The second option, 'window.open("?","_self"); f.submit();', relaunches my application in the same tab. This situation is unique because the JS code that Sherzod provided calls a URL and passes parameters to it. The examples provided in the above search link do not show how this can be done. Okay, I'll tell you how I did to make this work in my application: I open a url with parameters and after logging in these parameters disappear. procedure TMainForm.UniFormActivate(Sender: TObject); var newURL : String; begin newURL := 'https://www.google.com' UniSession.AddJS( // Current URL: UniSession.ARequest.Referer 'const nextURL = ''' + newURL + ''';' + 'const nextTitle = ''' + UniServerModule.Title + ''';' + 'const nextState = { additionalInformation: ''Updated'' };' // 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; Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 How do I pass parameters with the new URL? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 11 minutes ago, Frederick said: How do I pass parameters with the new URL? I use this to clear data in parameters: newURL := UniSession.ARequest.Referer; newURL := StringReplace (newURL,'&MyParams1=' + UniMainModule.CommandLine.Values ['MyParams1'],'',[rfReplaceAll]); newURL := StringReplace (newURL,'&MyParams2=' + UniMainModule.CommandLine.Values ['MyParams2'],'',[rfReplaceAll]); UniSession.ARequest.Referer := newURL; You can use just add params, like example: var Yourparam1, Yourparam2 : String; Yourparam1 := 'Name1=value1'; Yourparam2 := 'Name2=Value2'; newURL := 'https://www.google.com/?' + YourParam1 + '&' + Yourparam2; UniSession.AddJS(...... Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 46 minutes ago, irigsoft said: Okay, I'll tell you how I did to make this work in my application: I open a url with parameters and after logging in these parameters disappear. procedure TMainForm.UniFormActivate(Sender: TObject); var newURL : String; begin newURL := 'https://www.google.com' UniSession.AddJS( // Current URL: UniSession.ARequest.Referer 'const nextURL = ''' + newURL + ''';' + 'const nextTitle = ''' + UniServerModule.Title + ''';' + 'const nextState = { additionalInformation: ''Updated'' };' // 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; I tried this but the web browser throws an Ajax error and says that "the operation is insecure". Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 10 minutes ago, Frederick said: I tried this but the web browser throws an Ajax error and says that "the operation is insecure". I don't know why the browser generates an Ajax error. you may be trying a specific url (like google.com) and this hidden URL replacement is not OK for this website (or browser, can You try with other browser ?) I only use it in my application to remove some parameters. Maybe my example is not suitable for your purposes. But I'm sure it's suitable for the video example Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 I am not sure myself but I get Ajax errors on both Edge and Firefox browsers. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 1 minute ago, Frederick said: I am not sure myself but I get Ajax errors on both Edge and Firefox browsers. Thanks anyway. I have (and test) it on my mobile phone Browser and Google Chrome. Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 It could be localhost:8087 crossing to www.google.com that is throwing up the error. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 10 minutes ago, Frederick said: It could be localhost:8087 crossing to www.google.com that is throwing up the error. maybe that's the reason, but if you try Sherzog's example, it will happen too. Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 2 minutes ago, irigsoft said: maybe that's the reason, but if you try Sherzog's example, it will happen too. Surprisingly, Sherzod's example does not cause any problems and works fine except that I want the new URL to appear in my application's tab. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 9, 2021 Share Posted December 9, 2021 2 minutes ago, Frederick said: Surprisingly, Sherzod's example does not cause any problems and works fine except that I want the new URL to appear in my application's tab. I am sorry, only with that I could help. If @Sherzod can adapt my code to your needs, I guess it will be useful. Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 9, 2021 Share Posted December 9, 2021 That's alright. Thank you for your help. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 11, 2021 Share Posted December 11, 2021 On 12/9/2021 at 10:49 AM, Frederick said: It could be localhost:8087 crossing to www.google.com that is throwing up the error. If this is Your error ?: here is why: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy , https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS , https://fetch.spec.whatwg.org/#http-cors-protocol Maybe this is some kind of solution: https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf , https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 11, 2021 Share Posted December 11, 2021 @Frederick, can I ask you why you need to load google.com into your URL? What exactly needs to be achieved? maybe XMLHttpRequest will be better or use iFrame in your page. Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 11, 2021 Share Posted December 11, 2021 45 minutes ago, irigsoft said: @Frederick, can I ask you why you need to load google.com into your URL? What exactly needs to be achieved? maybe XMLHttpRequest will be better or use iFrame in your page. The Google URL address is just an example only. The main objective is to load any web site in the same tab as my application. The real target URL is a payment gateway. Essentially, when I click the button, my application closes and the new URL address appears in the same tab. I thought more of this and if the JS code is meant to do a POST of parameters to a URL address, it may not be possible to have it appear in the same tab as my application. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 11, 2021 Share Posted December 11, 2021 11 minutes ago, Frederick said: The real target URL is a payment gateway. All the problems with my example are CORS. What payment gateway are you using, if I may ask? I developed a self-service terminal and integrated Stripe's Checkout Quote Link to comment Share on other sites More sharing options...
Frederick Posted December 11, 2021 Share Posted December 11, 2021 2 minutes ago, irigsoft said: What payment gateway are you using, if I may ask? The problem is not specified to any payment gateway. If I call a URL address like https://www.somedomain.com/?userID=fred&password=mypass, I want the parameters to be hidden (this is achieved by Sherzod's JS code) and I want this URL address to appear in place of my application. 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.