You must Sign In to post a response.
  • Category: Windows

    How to call a java scriptfile

    i have winform HTMl editor.i have add a javascript file in html editor.
    how to call that javascript file in my web browser1 .how to call that jss file.
    i have written in jss file dynamic create HTML controls.
    so how to call that jss file.
  • #460458
    Can explain little more? You want to call JS file in HTML Editor or in the output HTML?
    Thanks
    Anuraj

  • #460467
    i want to call JS file in HTML Editor.when i editing a html page i need add that html controls.now im added just sample use java script.
    my coding is:
    *add reference COM :Microsoft HTML Object Library:
    -----------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using mshtml;
    using System.IO;
    using System.Reflection;

    namespace htmleditor
    {
    public partial class Form1 : Form
    {

    private IHTMLDocument2 doc;


    public Form1()
    {
    InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)
    {



    webBrowser1.DocumentText = "<html><body></body></html>";

    doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
    doc.designMode = "Off";

    }


    private void button1_Click(object sender, EventArgs e)
    {



    HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
    HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
    IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
    element.text = "function sayHello() { alert('hello') }";
    head.AppendChild(scriptEl);
    webBrowser1.Document.InvokeScript("sayHello");
    }


    -----------------------------------------------------------


    i want add this java script: is

    function addInput()
    {
    var x = document.getElementById("inputs");
    x.innerHTML += "<input type=\"text\" />";
    }

  • #460470
    Check this link : http://stackoverflow.com/questions/153748/webbrowser-control-from-net-how-to-inject-javascript

    Try

    HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
    HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
    IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
    element.text = "function sayHello() { alert('hello') }";
    head.AppendChild(scriptEl);
    webBrowser1.Document.InvokeScript("sayHello");

    Thanks
    Anuraj

  • #460482
    i want add this java script:
    how to use it its raise some Errors.

    function addInput()
    {
    var x = document.getElementById("inputs");
    x.innerHTML += "<input type=\"text\" />";
    }


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.