简体   繁体   English

如何在内容中获取脚本,请参见下面的示例

[英]how to get script inside content see example below

I want to get content of script tag example 我想获取脚本标签示例的内容

now see above in src property load bolo7.com content i want to catch that contain i have try so many method but it doesn't work 现在在src属性中看到上面的内容,加载bolo7.com内容,我想捕获包含的内容,我尝试了很多方法,但是没有用

try 1 -> document.getElementById("data").innerHTML; 尝试1-> document.getElementById(“ data”)。innerHTML; //doesn't work //不起作用

try2 -> document.getElementById("data").text; try2-> document.getElementById(“ data”)。text; //doesn't work //不起作用

if you are intelligent in javascript please give me answer that how to get content of script inside content 如果您精通javascript,请给我答案,如何获取内容中的脚本内容

thanks in advance for your answer my website is : http://www.bolo7.com/ 在此先感谢您的回答,我的网站是: http : //www.bolo7.com/

The text property defined by the HTMLScriptElement interface is the text content of the script element. HTMLScriptElement接口定义的text属性是脚本元素的文本内容。 If the element uses a src attribute, it should not have any content so its text property will be an empty string. 如果元素使用src属性,则它不应包含任何内容,因此其text属性将为空字符串。

In that case, you will need to access the src some other way, perhaps XMLHttpRequest will suit. 在这种情况下,您将需要以其他方式访问src,也许XMLHttpRequest适合。

Note also that the id attribute for script elements is not valid for the DOCTYPE being used at the linked resource (and the document is invalid ). 还要注意,脚本元素的id属性对于在链接资源处使用的DOCTYPE 无效 (文档无效 )。

Something like this? 像这样吗

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        //some data here
        function add1(x) {
            return 1 + x;
        }
    </script>
    <script type="text/javascript">
        alert(document.getElementsByTagName("script")[0].innerHTML);
    </script>
</head>
<body>

</body>
</html>

but RobG is right, only works for inline javascript. 但RobG是正确的,仅适用于内联JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM