获取< script>的内容标签 [英] Getting content of <script> tag

查看:89
本文介绍了获取< script>的内容标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在html中获取< script> 标记的内容:

I am trying to get content of <script> tag in html:

我可以获得<使用jquery $(script)$ h $()

但如何获取
的内容< script src ='something.js'>< / script>

but how to get content of <script src='something.js'></script> ?

推荐答案

这是怎么回事。

$.get("/something.js",function(scriptContent){alert(scriptContent)});

它将通过ajax请求提取内容

It will pull the content through an ajax request

或者,您可以通过向便于在服务器上加载JS文件的页面发出请求来提取服务器上的内容并将其返回给客户端。如果js文件托管在不同的域

Alternatively, you can pull the content on the server and return it back to the client by making a request to a page that facilitates the loading of the JS file on the server. This is necessary if the js file is hosted under a different domain

这篇关于获取&lt; script&gt;的内容标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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