0

Is in windows phone equivalent of IOS method called loadHTMLString:baseURL or android loadDatawithBaseUrl (here). I want to run script on website and that is why I need this base url to be invoked.

Community
  • 1
  • 1
Maximus
  • 3,458
  • 3
  • 16
  • 27

1 Answers1

-1

By looking at the reference link, I think what you are trying to achieve is a web browser control on Windows Phone to display a remote HTML page on the app page.

  • LOAD FROM REMOTE URL:

Step 1: Load WebBrowser control on your app page from the Toolbox on page.xaml

<Grid x:Name="ContentGrid" Grid.Row="1">
    <phone:WebBrowser HorizontalAlignment="Left" Margin="0,0,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="800" Width="470" />
</Grid>

Step 2: Write C# code (you can even use VB.NET) on page.xaml.cs

webBrowser1.Source = new Uri("http://www.foo.com", UriKind.Absolute);
  • LOAD FROM LOCAL HTML STRING

Here Step 1 remains the same, just to load an HTML code locally:

Step 2: C# Code on page.xaml.cs

String htmlContent = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
  <head>
  <meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">
  <meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\">  
  <title></title>
  </head>
  <body id=\"body\">  
  <!-- The following code will render a clickable image ad in the page -->
    <script src=\"http://www.myscript.com/a\"></script>
  </body>
</html>";

webBrowser1.NavigateToString(htmlContent); //This renders the HTML string defined above in the webview.

EDIT: Also, if you want to allow scripts to execute in the webview, set IsScriptEnabled property of the webbrowser control to true.

webBrowser1.IsScriptEnabled = true;
Rishi Jasapara
  • 638
  • 9
  • 33
  • I have some script from website X. In order to run those script I need to retrieve another scripts, styles etc. from that website so my aim was to run website (to be able to use those required elements) and run that script. – Maximus Mar 11 '15 at 07:37
  • @Maximus: your description seems vague. Can you explain with some pseudo. I will get a better idea to help you :) – Rishi Jasapara Mar 11 '15 at 08:08
  • I've been trying to do this same thing, and it doesn't appear to be possible. There is a BaseUrl property, but it is read only. – wshelor Dec 30 '16 at 21:02
  • Okay, so here is (sort of) how we did this: You can add a html tag to the file, and it will look for resources in that location. For us, it looked like . This let us load local resources. However, we ran into another problem, as NavigateToStream does not allow scripts to be run. – wshelor Jan 03 '17 at 23:44