locked
Xamarin Forms Webview doesn't show the tradingview widget. RRS feed

  • Question

  • User380602 posted

    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.

    Wednesday, February 13, 2019 5:21 PM

All replies

  • User369979 posted

    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.

    Friday, February 15, 2019 7:15 AM
  • User380602 posted

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

    Thank you for the reply

    Friday, February 15, 2019 8:59 AM
  • User380602 posted

    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 :

    Monday, February 25, 2019 5:15 PM
  • User380602 posted

    Code from xaml :

    Monday, February 25, 2019 5:16 PM
  • User390319 posted

    I have the same problem you solved it?

    Monday, November 11, 2019 1:48 PM
  • User380602 posted

    No, i don't. I just stop trying. If i get involved again, i will post a solution.

    Thursday, December 12, 2019 1:27 PM
  • User395570 posted

    I have it working. See LiLo.Lite as the code is Open Source. There are things still to be improved, but it works!

    Friday, July 3, 2020 3:22 PM