Jump to content

Hide Parameter


clement

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...