0

I'm building an app using ionic and a REST API backend. One of my requests involve redirection to a payment gateway. And this AJAX request returns a webpage. How do I display that in an inapp browser ?

Or, I could directly post the form to the server and display the page, but in that situation we are unable to close this server page upon completion. Any help is appreciated ! Thank you :)

  • Can you clarify what you mean by „returns a webpage“, you mean a complete HTML structure? Re „unable to close this server page upon completion“, can you clarify why? (as any solution we offer might have the same problem) – Pekka Oct 06 '16 at 10:59
  • @pekka , the issue is that, my app is completely hybrid. This particular request to the REST API redirects to a payment gateway and I need to display this payment gateway page inside my cordova inapp browser and all future requests are handled by the gateway and not from the app. The inapp browser needs a URL for it to display the page, but this API just returns a html. structure and it can't be displayed anywhere. I tried to post the form in the old fashioned way (non Ajax)but the response page just overlaps the application and I am not able to close this response page when payment is done. – Akshay S Menon Oct 06 '16 at 12:11
  • Hmm, weird. That’s a strange thing, sending an entire page structure as an Ajax response. Couldn’t you just tell the Javascript making the request to replace the current document with the Ajax result though? I don’t know anything about Cordova and ionic, but it should work, see [here](http://stackoverflow.com/questions/483745/replace-html-page-with-contents-retrieved-via-ajax) for how to do it, niutech’s answer. – Pekka Oct 06 '16 at 12:41
  • Thank you for the input ! I know it's a weird response I am getting. The issue still doesn't end with me replacing my document body with the response. U see the gateway only accepts requests from one particular URL, and I need to load that as a URL in my inapp browser. – Akshay S Menon Oct 06 '16 at 12:58
  • I’m not sure I understand. The response needs to have a certain URL outside your control? That’s not going to be possible. – Pekka Oct 06 '16 at 13:17
  • Let's call the gateway abc.com . What I have to do is just make a call to the REST API and the API redirects to abc.com. this redirection only takes place after authentication from abc.com, so it is impossible for me to directly load the abc.com URL from inapp browser . – Akshay S Menon Oct 06 '16 at 15:01
  • Hmm, sounds like an old fashioned request would be the best way to go. I don’t understand this bit with the response page overlapping the application. Can you expand on what happens there? – Pekka Oct 06 '16 at 15:09
  • Ok so, this is a completely hybrid application so I have not hosted the pages (UI html pages) on any server. They are directly being taken from the apk. When I do an old fashioned request the server successfully displays a page which forms an overlay to the app. The app has no control over that page anymore. I did it using form submit, target = _blank. So once the payment is done, we are not able to shift the control back to the application from the serve page. A normal JavaScript window.close() is not working on that server page – Akshay S Menon Oct 06 '16 at 15:14
  • Why not remove the `target=blank`? Would that not leave things in the same window? Or are you saying you’re making the request from your app and aren’t using a web control at all? – Pekka Oct 06 '16 at 15:17
  • Even if I remove the _blank, the new server page just loads on top of the current app, the JavaScript of my app does not have any control over that window. That window is completely controlled from the server (including the scripts) – Akshay S Menon Oct 06 '16 at 15:23
  • Ah, OK, I see. Have you tried creating an ` – Pekka Oct 06 '16 at 15:31
  • I did consider the idea of iframe , but does the iframe allow the page to be dynamically loaded / redirected / closed as and when the server wishes it to ? – Akshay S Menon Oct 06 '16 at 15:33
  • loaded, yes. Redirected, only by setting `location.href`. Closed, yes. You won’t be able to touch the contents inside the iframe if you’re in a normal web browser setting, though - they’re protected by the Same Origin rule. – Pekka Oct 06 '16 at 15:47
  • 1
    Well then I guess that rules out iframe :( will check it out and let u know though ! Do keep checking this post :) cheers ! – Akshay S Menon Oct 06 '16 at 16:10

0 Answers0