Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to insert javascript funtion dynamically ?

How to insert javascript funtion dynamically ?

Scheduled Pinned Locked Moved C#
tutorialjavascripthelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jacobb Michael
    wrote on last edited by
    #1

    Hi all, I have added IHtmlscriptElement ( a javascript function ) now i want to attach and event for the body tag For example, in the initial ............. Dynamically i want to add as bellow ............. How to add as above Please some one help me thanks in advance

    L 1 Reply Last reply
    0
    • J Jacobb Michael

      Hi all, I have added IHtmlscriptElement ( a javascript function ) now i want to attach and event for the body tag For example, in the initial ............. Dynamically i want to add as bellow ............. How to add as above Please some one help me thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      do u want from .cs file thanks , amit

      J 1 Reply Last reply
      0
      • L Lost User

        do u want from .cs file thanks , amit

        J Offline
        J Offline
        Jacobb Michael
        wrote on last edited by
        #3

        Hi Friend, thanks, yes i am doing in C# application only if you guide me it will be much helpful for me. thanks again

        L 1 Reply Last reply
        0
        • J Jacobb Michael

          Hi Friend, thanks, yes i am doing in C# application only if you guide me it will be much helpful for me. thanks again

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          hi, from .cs file u can use this I hope this will help u out

          Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "unSelectCheckbox();", true);

          Thanks, Amit Patel

          J 1 Reply Last reply
          0
          • L Lost User

            hi, from .cs file u can use this I hope this will help u out

            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "unSelectCheckbox();", true);

            Thanks, Amit Patel

            J Offline
            J Offline
            Jacobb Michael
            wrote on last edited by
            #5

            Hi Friend, Thank you, I am using web browser control, in windows application, so i get all the HtmlElement like body,form,div etc... from there i want to attache this. have a look at my code

            mshtml.IHTMLElementCollection ecol = document.all;//getElementsByTagName("head");
            if (ecol != null)
            {
            foreach (IHTMLElement elmnt in ecol)
            {
            string str = elmnt.outerText;
            int k = 0;
            if (elmnt.ToString() == "mshtml.HTMLHeadElementClass")
            {
            mshtml.IHTMLHeadElement head = (mshtml.IHTMLHeadElement)elmnt;
            //mshtml.IHTMLElement se = document.createElement("script");
            mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)document.createElement("script");
            //element.text = "alert('here we are')";
            element.text ="function EventRaise(){var m = document.activeElement.value;alert(document.activeElement.type);alert('The active element is '+m); }";
            IHTMLDOMNode node = (IHTMLDOMNode)element;
            document.appendChild(node);

                                    }
                                    else if (elmnt.ToString() == "mshtml.HTMLBodyClass")
                                    {
            
                                        //need to call the EventRaise function
                                    }
                                }
                            }
            

            i hope you may have some idea on that... awaiting...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups