0

I have a script tag e.g

<script>document.write(<p>This is a test</p>)</script> 

as a string, so I need the full html(when it will load on web browser) as string in web api method For eg

 public string GetHTML()
    {
        string script = "<script>document.write(<p>This is a test</p>)</script>";
        string html = "<html><head></head><body><script>document.write(\" <p> Hiiiiiiiii </p> \")</script><p>Hiiiiiiiii</p></body></html>";//Here i want some processing which return this kind of value
        return html;
    }

I have tried most of the things like convert the view into string, create a request with webclient to view but I got the html without javascript executed.

I have also look into headless browsers but couldn't get it compatible with webapi.

UPDATE 23/Sep/2016 : I pardon that I am unable to clear the question.Actually it is not much more related to mvc or web api .My core requirement is that i have a html string as described above so i need a c# code to get the html which have javascript executed. For e.g.

 string Inputhtml = "<html><head></head><body><script>document.write(\" <p>Hiiiiiiiii</ p > \")</script></body></html>";
            string Outputhtml = "<html><head></head><body><script>document.write(\" <p>Hiiiiiiiii</ p > \")</script><p>Hiiiiiiiii</p></body></html>";

So in output html there is a p tag which is written by javascript. I hope now question makes more sense.

DSP
  • 78
  • 10
  • Is this related to ASP.NET Web API or ASP.NET MVC? If so, then please add the relevant tag: [asp.net-mvc] or [asp.net-web-api]. – ekad Sep 22 '16 at 01:51
  • If you are referring to ASP.Net Web API, what you are describing doesn't make sense, because APIs should never be designed to expect the calling source to be anything specific. (i.e. an API can't control a browser if the caller isn't a browser, so don't design the API to do that). – Claies Sep 22 '16 at 02:19
  • aside from that, the API isn't responsible for making the script be processed anyway. If the `GetHTML` method on the API returned this arbitrary HTML to a browser and the browser didn't execute it, that's an issue on the browser side code that requested the information, not a problem with the API. If this is the *only* way you can accomplish your task, then you should show the consuming code, not the sending code. – Claies Sep 22 '16 at 02:22
  • I am not rendering it in browser ,i want that html when we rendered above html in browser. – DSP Sep 23 '16 at 05:17

0 Answers0