Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The WebBrowser dose not fire any java scripts; Here it is one of them:
C#
public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    this.Document.InvokeScript("postform_open");
}

Even when I click on the link below in the WebBrowser:
HTML
<a onclick="postform_open();">Send</a><%--This html code cames from My Browser inspector--%> 

What should I do to fix it? What I am missing?

For understanding that can I invoke an script or not I created a new project with only to Control. A button and a webBrowser; All of the code are just these:
C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            wb.ScriptErrorsSuppressed = true;

            wb.DocumentText = @"<html><head>
                <script type='text/javascript'>
                    function doIt() {
                        alert('hello again');
                        return 'i did it!';
                    }
                </script>
                </head><body>hello!</body></html>";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            object x = this.wb.Document.InvokeScript("doIt");
        }
    }

the variable x will be null and no alert will appear. I am really confused.
Posted
Updated 4-May-13 2:25am
v4

Use the below code to call a javascript function from cs

C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "Name", "postform_open()", true);


User the below code to call to call an javascript from html

HTML
<head>

<script>

function postform_open()
{
   // Your code here
}

</script>

</head>

<body>


<a href="" onclick="postform_open();">Send</a>

</body>
 
Share this answer
 
Comments
Meysam Toluie 30-Apr-13 4:11am    
I think you are miss understanding. The web site is not mine! and of course its my fault to not explaining well.
My Project is Windows Application.
I am trying to invoke a javascript in a website using WebBrowser.
Jithin Geroge 30-Apr-13 4:50am    
Sorry .. Its my mistake ...I think its for web application
Meysam Toluie 1-May-13 4:32am    
Thank you anyway!
Just one word is the answer:
"VS Service Pack 1"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900