How to execute javascript in C#? [duplicate]
Possible Duplicate:
Embedding JavaScript engine into .NET (C#)
I have a script like this:
var myObject=new Object();
myObject="Hello";
If I refer the script in browser, I can make use of myObject just like below:
<script src="myObject.js" type="text/javascript">
<script type="text/javascript">
alert(myObject);
</script>
Can I execute the script in C# without br开发者_JAVA技巧owser? It should be like below:
//These are C# Code
string result = ????????
not getting your question properly i think you are using the term browser in place of html if it' so then there is a method Page.RegisterClientScriptBlock();
for more detail read on http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx
you can use this in whicever event you want to run the script .
not that i assumed browse==HTML code
Have you checked Page.ClientScript.RegisterStartupScript()
method http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx
the page have an examples
Well,
i think you're a bit confused. try first to understand the difference between Client side-script and Server-side code.
Basically server-side produces the rendered html for client-side(your browser).
It is not possible to create objects like your example, you have to use JSON to get objects from server.
but if you what to get the object value on c#, you must send it to the server, on a and parse it on your server side
精彩评论