Reputation: 1414
In my app I want to load an html that contains an iframe with a remote url. This html is always the same, except for the iframe's src. What I do is hold the html in a string, and fill in the iframe url, than call NavigateToString(html). I get the iframe url from a REST API. I also get a baseUrl. If I merge those two urls into an absoulute url and set that as the iframe's src, the page won't load due to security reasons (it's a payment page). But if I set it without baseUrl, of course, the webview has no idea what's the baseUrl is, and the page also won't load.
In Android one could simply call webView.loadDataWithBaseURL. Is there something like this in Windows Phone 8.1? Any workaround?
(The problem is further complicated by that I also have to set Cookies to the webview.)
Upvotes: 2
Views: 1063
Reputation: 1414
I came up with a solution, which works, and actually it's less hacky than it seemed to me at first.
I skipped NavigateToString. By using NavigateWithHttpRequestMessage, I can send a request to an URL, for example http://mybackend.com. I can set cookies as well (more information on this: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/a451d411-9312-4d40-80ee-112e166144ab/how-to-send-auth-cookie-in-webview-request?forum=winappswithcsharp). So far I have:
base URL set
cookies set.
Though, I haven't set my local html string yet. For this, in the WebView's NavigationCompleted event, I run a JS script like this:
await wvSecurePay.InvokeScriptAsync("eval", new string[] { "document.getElementsByTagName('html')[0].innerHTML = '" + htmlToLoad + "';"})
This will replace the current html content with the one I want to load. So I have my html containing the iframe with the relative url on a page which has the domain I need.
Upvotes: 5