Jump to content

Recommended Posts

Posted

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.

  • 4 years later...
Posted
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.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

Posted
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.

Posted
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;

Posted
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(......

 

 

Posted
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".

Posted
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

Posted
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.

Posted
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.

Posted
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.

Posted
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.

Posted
Posted
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.

Posted
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

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...