页面源代码中的运行时脚本 [英] Runtime Script in Page Source

查看:115
本文介绍了页面源代码中的运行时脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我遇到了一个问题,我想在页面上添加运行时脚本,而且我必须在页面源代码中显示此脚本,而无需重新渲染页面,请问一下答案吧,因为这非常紧急.


我已经按照以下方式进行了编码:

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 :

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);



而且我也使用jQuery完成了同样的工作,但是我无法在页面源代码中添加代码.

请考虑:
1)我也无法刷新我的页面,因为它完全基于WCF服务请求.
1)我不能使用ScriptManager类.


Banshi



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

推荐答案

我不确定以这种方式添加脚本节点时所有浏览器都将执行脚本.

下载后,您可能会发现jQuery正在执行脚本.

我有一个类似的要求,即通过AJAX加载的任何数量的组件都需要不同的脚本.

我从响应中提取脚本元素并执行它们.您的问题要简单一些,因为整个请求响应都是一个脚本.以下文章显示了如何执行AJAX收集的脚本.

我建议使用AJAX来获取jQuery脚本内容,然后使用类似于以下方法的方法来运行它:

http://manikandanmv.wordpress .com/2008/09/26/how-to-execute-the-scripts-in-ajax-responsehtml-with-scripts/ [
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/[^]


是的,您可以通过这种方式添加脚本.但是您无法将其显示在页面源中.
您动态添加到页面的所有内容都不会显示在页面源中.

例如document.getElementById("some-element-id").innerHTML =< p> Hello world</p>";将不会显示在页面源中;

但是,您可以使用Chrome的开发工具或FireBug等插件查看动态操作的结果.
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.


这篇关于页面源代码中的运行时脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆