locked
Why the WebView doesn't load any script?

    Question

  • I have been trying to invoke some scripts that I have in local and jQuery plugins but it seems that no one works, even I tried to launch a simple alert and nothing happened. These are my codes.

    XAML:

    <Page
    x:Class="Test_HMTL.Pages.TipsResult"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Stop_Diabetes.Pages"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="#227EC2">
    
    <Grid Background="White">
        <Grid>
            <WebView x:Name="miniBrowser" HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch" />
            <Image x:Name="imgName" Source="ms-appx:///Assets/Images/ComingSoon.png" Visibility="Collapsed"/>
        </Grid>
    </Grid>
    <Page.BottomAppBar>
        <CommandBar x:Name="appBar" Background="#227EC2" RequestedTheme="Dark" ClosedDisplayMode="Minimal">
            <CommandBar.SecondaryCommands>
                <AppBarButton x:Name="menuRating" Label="rate this place!" Click="menuRating_Click"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    C#

    protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                Type = ((string)e.Parameter).Replace("tile", "");
    
                if (Type == "Tips")
                    imgName.Visibility = Windows.UI.Xaml.Visibility.Visible;
                else
                    miniBrowser.NavigateToString(getBody());
            }
        }
    
        private string getBody()
        {
            string body;
            body = @"<!DOCTYPE html><html lang='en'>
    <head>
        <meta charset='utf-8' />
        <meta name='viewport' content='width=device-width, initial-scale=1'>
        <link rel='stylesheet' href='ms-appx-web:///Assets/jquery/css/themes/default/jquery.mobile-1.4.5.min.css' />
        <link rel='stylesheet' href='ms-appx-web:///Assets/jquery/css/jquery.rateyo.min.css' />
        <script src='ms-appx-web:///Assets/jquery/js/jquery.min.js'></script>
        <script src='ms-appx-web:///Assets/jquery/js/jquery.mobile-1.4.5.min.js'></script>
        <script src='ms-appx-web:///Assets/jquery/js/jquery.rateyo.min.js'></script>
        <title></title>
    
        <script>
            $(function () { 
                $('#rateYo').rateYo({
                    rating: 5.0,
                    readOnly: true
    
                });
            });</script>
    </head>
    <body><h3>" + Type + @"</h3>
        <ul data-role='listview' data-inset='true' data-filter-placeholder='Search recipies...' data-filter='true'>
            <li><a href='";
    
            switch (Type)
            {
                case "Recipies":
                    body += "http://m.allrecipes.com/recipes/739/everyday-cooking/special-diets/diabetic/?page=1'>allrecipies";
                    break;
                case "Diets":
                    body += "http://mobile.eatingwell.com/nutrition_health/weight_loss_diet_plans/diet_meal_plans/7_day_diabetes_meal_plan'>Eating Well";
                    break;
                case "Exercises":
                    body += "http://weighttraining.about.com/od/weighttrainingforhealth/a/diabetesworkout.htm'>about health";
                    break;
            }
    
            body += @"<div data-role='none' id='rateYo'></div>
            </a></li>
        </ul>    </body></html>";
            return body;
        }

    Sorry for the question but I haven't found any good solution, I think it's something related to JS maybe it's not enabled because as I said before I couldn't do a simple alert and this control doesn't have any option such as IsScriptEnabled like WebBrowser from Windows Phone 8. Thanks in advance for your worthy knowledge.




    Federico Navarrete

    Monday, April 13, 2015 11:36 AM

Answers