Xamarin Forms Webview doesn't show the tradingview widget.

DenniroDenniro Member ✭✭

Hi all,

I use a widget from tradingview site. I would like to make this implementation using xamarin forms webview. However i can't make it works. It just doesn't appear the widget at all.

The same piece of code woks correctly on a browser.
In the html code there is a script tag which the source file is from external resources(from their site).
So i would like to ask if the webview can load javascript resources from the web.

Any help will be appreciated.

Thanks in advance!

I would copy&paste the code but the forum doesn't allow me because every time i paste the code a captcha appear to check if i am human . When i click the check button the whole text disappeared. I try to post code like an answer of this question.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    If the browser supports your web I think the webview should show that widget.
    You can try to open your webpage on the phone's system browser to see if the widget can be displayed.
    Moreover, codes can be more helpful for finding out your issues. Maybe you've tried too many times to post the code, you can try to post it later.

  • DenniroDenniro Member ✭✭

    I can not post code at the comment section yet. So i attached as a file.

    Thank you for the reply

  • DenniroDenniro Member ✭✭

    Code from cs file:
    public MainPage()
    {
    InitializeComponent();
    var htmlSource = new HtmlWebViewSource();

            htmlSource.Html = @"<!DOCTYPE html>
            <html lang=""en"">
            <head>
              <meta charset = ""UTF-8"">
               <meta name = ""viewport"" content = ""width=device-width, initial-scale=1.0"">
               <meta http - equiv = ""X -UA-Compatible"" content = ""ie=edge"">  
                    <title> Document </title>
            </head>
            <body>         
           <!-- TradingView Widget Start -->
            <div class=""tradingview -widget-container"">
                <div id = ""tradingview_58186""></div>
                <div class=""tradingview -widget-copyright"" ><a href = ""https://www.tradingview.com/symbols/NASDAQ-AAPL/"" rel =""noopener"" target =""_blank"" ><span class=""blue -text"" > AAPL chart</span></a> by TradingView</div>
            </div>
            <!-- TradingView Widget END -->
            <script type = ""text /javascript"" src = ""https://s3.tradingview.com/tv.js"" ></script>
            <script type= ""text /javascript"">
                 new TradingView.widget(
    
                 {
              ""width"": 980,
              ""height"": 610,
              ""symbol"": ""NASDAQ:AAPL"",
              ""interval"": ""D"",
              ""timezone"": ""Etc /UTC"",
              ""theme"": ""Light"",
              ""style"": ""1"",
              ""locale"": ""en"",
              ""toolbar_bg"": ""#f1f3f6"",
              ""enable_publishing"": false,
              ""allow_symbol_change"": true,
              ""container_id"": ""tradingview_58186""
               }
                 );
              </script>
            </body>
            </html>";
            webView.Source = htmlSource; 
        }
    

    Code from xaml :


  • DenniroDenniro Member ✭✭

    Code from xaml :


Sign In or Register to comment.