Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

i am facing a problem that i want to add run time script on the page as well as i have to show this in page source without re-render the page can you please post the answer since it is pretty urgent please...


I have already code in the following manners :

JavaScript
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'Scripts/jquery-1.4.1.min.js';
head.appendChild(script);


and i have also done the same using jQuery this works but i am unable to add the code in page source .

Please consider that:
1) I cant refresh my page as well since it totally based on WCF Service request .
1 )I cant use ScriptManager Class.


Banshi
Posted

I'm not sure all browsers will execute the script when adding the script node in this way.

You'll probably find jQuery is executing the script once it's downloaded.

I have a similar requirement where any number of components loaded via AJAX require different scripts.

I extract the script elements from the response and execute them. You're problem is slightly simpler as the entire request response is a script. The following article shows how to execute scripts collected by AJAX.

I'd suggest using AJAX to get the jQuery script content and there run it using a method similar to this:

http://manikandanmv.wordpress.com/2008/09/26/how-to-execute-the-scripts-in-ajax-responsehtml-with-scripts/[^]
 
Share this answer
 
Yes you can add a script this way. But you cannot have it show up in the page source.
None of the things you dynamically add to the page show up in the page source.

e.g. document.getElementById("some-element-id").innerHTML="<p>Hello world</p>"; will not show in the page source;

You can however see the result of dynamic actions with the development tools of Chrome or with plugins like FireBug.
 
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