2

I am building an application in react native. I have a use case where I have to open some eSinger gateway (like payment gateway open in the web application). in this gateway, I have to post form with PDF file's base64 data from the background so they can redirect me to their gateway page, but sometimes a string of HTML which I use to render this page is too large and it breaks the web view.

The code in the render() of the component is:

<WebView
   source={{html: this.state.data}}
   scalesPageToFit={true}
   onNavigationStateChange={ this.onNavigationStateChange.bind(this) }
 />

I am initialise data in constructor with the string like:

let data = `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><script type = "text/javascript" src = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Verigo</title></head><body style="margin-top:10%;margin-left:10%;margin-right:10%;"><form action="` + POST_URL + `" id="frmdata" method="post"><input id="File" Name="File" type="hidden"/><input id="Name" name="Name" type="hidden" value=""><input id="SelectPage" name="SelectPage" type="hidden" value="ALL"><input data-val="true" data-val-number="The field SignatureType must be a number." data-val-required="The SignatureType field is required." id="SignatureType" name="SignatureType" type="hidden" value="3"><input id="SignaturePosition" name="SignaturePosition" type="hidden" value="Customize"><input id="AuthToken" name="AuthToken" type="hidden" value=""><input id="PageNumber" name="PageNumber" type="hidden" value=""><input id="Data" name="Data" type="hidden" value=""><input id="FileType" name="FileType" type="hidden" value="PDF"><input data-val="true" data-val-required="The PreviewRequired field is required." id="PreviewRequired" name="PreviewRequired" type="hidden" value="True"><input id="CustomizeCoordinates" name="CustomizeCoordinates" type="hidden" value=""><input id="PagelevelCoordinates" name="PagelevelCoordinates" type="hidden" value=""><input id="ReferenceNumber" name="ReferenceNumber" type="hidden" value=""><input id="IsCosign" name="IsCosign" type="hidden" value=""><input id="SUrl" name="SUrl" type="hidden" value=""><input id="CUrl" name="CUrl" type="hidden" value=""><input id="FUrl" name="FUrl" type="hidden" value=""><center style="position:absolute;top:35%;left:5%"><div><img src="/Content/Img/ajax-loader.gif"><div><p style="font-size:15px;">Redirect to Aadhaar OTP screen.Please don't cancel or press back.This process can take some time.</p></div></div></center></form><script type="text/javascript">$(document).ready(function () {$('#ReferenceNumber').val('` + this.props.transaction_id + `');$('#FileType').val('PDF');$('#File').val('` + this.props.base64 + `');$('#Name').val('` + this.props.sign_payload.user_name + `');$('#AuthToken').val('` + this.props.auth_token + `');$('#SignatureType').val('3');$('#SelectPage').val('ALL');$('#SignaturePosition').val('Customize');$('#PageNumber').val('');$('#PagelevelCoordinates').val('');$('#CustomizeCoordinates').val('` + [this.props.sign_payload.yx, this.props.sign_payload.yy, 150, 150].join(",") + `');$('#PreviewRequired').val('False');$('#IsCosign').val('True');$('#SUrl').val('` + surl + `');$('#FUrl').val('` + furl + `');$('#CUrl').val('` + curl + `');$('#frmdata').submit();});</script></body></html>`

Main javascript code in above HTML is:

$(document).ready(function () {$('#ReferenceNumber').val('` + this.props.transaction_id + `');$('#FileType').val('PDF');$('#File').val('` + this.props.base64 + `');$('#Name').val('` + this.props.sign_payload.user_name + `');$('#AuthToken').val('` + this.props.auth_token + `');$('#SignatureType').val('3');$('#SelectPage').val('ALL');$('#SignaturePosition').val('Customize');$('#PageNumber').val('');$('#PagelevelCoordinates').val('');$('#CustomizeCoordinates').val('` + [this.props.sign_payload.yx, this.props.sign_payload.yy, 150, 150].join(",") + `');$('#PreviewRequired').val('False');$('#IsCosign').val('True');$('#SUrl').val('` + surl + `');$('#FUrl').val('` + furl + `');$('#CUrl').val('` + curl + `');$('#frmdata').submit();});

When base64 of the file of size around 1 MB is working but after that is start breaking. my HTML string length is 4548156.

How much long HTML string i can pass to WebView?

Thanks in advance.

2
  • You seem to be setting the value as $('#File').val('+ this.props.base64+'); Is it really required? Why are you trying to inject so much data into the DOM? Commented Nov 9, 2017 at 8:46
  • 1
    Yes, I required posting base64 data to eSign POST API for redirecting me to their gateway page. Commented Nov 20, 2017 at 13:50

1 Answer 1

1

Data String that I was using for rendering the DOM is too long(due to base64) so it is not able to render. I solved it by calling my API which gives me base64 data in above javascript by ajax call and settings base64 to #File at runtime which solves this problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.