locked
s there any way I can load a HTML string (string_ that contains HTML code directly into the Web Browser? RRS feed

  • Question

  • Is there any way I can load a mstrHTML string (string_ that contains HTML code directly into the Web Browser? I'm using silverlight 4.0

    Dim  mstrHTML as Sting =<html><head> testing</head> </html>

    I'm trying like this but getting compile error.

    Dim urlStr As String = String.Format("window.open('{0}', '{1}', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,width=800,height=1200,left=50,top=50')",mstrHTML, "MyWindow")
    
    System.Windows.Browser.HtmlPage.Window.Eval(urlStr)


    • Edited by shilpi jaiswal Monday, July 10, 2017 11:55 AM
    • Moved by Stanly Fan Wednesday, July 12, 2017 9:34 AM from windows form general
    Monday, July 10, 2017 11:53 AM

All replies

  • Hi shilpi,

    >>there any way I can load a HTML string...directly into the Web Browser?

    This forum is discussing and asking questions about the Windows Form, so the Web Browser you mentioned is the control in the Winform? If so, you can display the HTML with the following code directly:

    private void Form3_Load(object sender, EventArgs e)
    {
          webBrowser1.DocumentText = "<html><head> testing</head> </html>";
    }   

    If no, please let me know how do you want to show the HTML.

    >>I'm trying like this but getting compile error.

    What error did you get? Please provide more details about this error message.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 11, 2017 2:31 AM
  • Thanks for reply but that won't work for me as I'm using Silverlight 4.0 InBrowser.

    Dim urlStr As String = String.Format("window.open('{0}', '{1}', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,width=800,height=1200,left=50,top=50')",mstrHTML, "MyWindow") System.Windows.Browser.HtmlPage.Window.Eval(urlStr)

    While using above code I'm getting "JS Compliler Error"

    as its passing value as

    window.open('<HTML xmlns="">

      </HEAD>
    </HTML>','MyWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,width=800,height=1200,left=50,top=50')

    & also I dnt want to save that HTML string as file i want to use it directly to open in Browser.Could you please help me out.

    Thanks


    Wednesday, July 12, 2017 6:29 AM
  • Hi shilpi,

    >>I'm using Silverlight 4.0 InBrowser.

    According to your description, your issue is more related about Silverlight. And this forum is discussing and asking questions about the Windows Form and ClickOnce, I will move this thread to corresponding forum: Silverlight Forum for dedicated information.

    Thank you for your understanding.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 12, 2017 9:32 AM

  • Hi shilpi jaiswal,

    >>also I dnt want to save that HTML string as file i want to use it directly to open in Browser.Could you please help me out.

    The following links for your reference.

    Silverlight and JavaScript Interop Basics :
    http://pietschsoft.com/post/2008/06/19/Silverlight-and-JavaScript-Interop-Basics

    Write to browser Javascript console from Silverlight in most browsers. Works with code outside of UI thread.
    https://gist.github.com/yoeun/994228

    You can also try the following way.

    // Load HTML document as a string
      Uri uri = new Uri(@"pack://application:,,,/HTMLDocumentWithoutScript.html", UriKind.Absolute);
      Stream stream = Application.GetResourceStream(uri).Stream;
      using (StreamReader reader = new StreamReader(stream))
      {
        // Navigate to HTML document string
        this.webBrowser.NavigateToString(reader.ReadToEnd());
      }


    WebBrowser.NavigateToString Method (String):
    https://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.navigatetostring(v=vs.110).aspx


    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Best Regards,

    Yohann Lu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 17, 2017 7:25 AM