Javascript 如何使用我的代码查找'script'元素?

Javascript 如何使用我的代码查找'script'元素?,javascript,dynamics-crm,microsoft-dynamics,Javascript,Dynamics Crm,Microsoft Dynamics,我在Dynamics 365表单上注册了JavaScript函数: 我的代码工作正常(结果是TypeScript传输): 但如果我试图找到包含我的代码的script元素,那么我什么也找不到。我在浏览器控制台(Google Chrome)中运行此代码: //在主文档内部搜索,子文档位于iFrame中: 让docs=[document]; for(设frameIndex=0;frameIndex

我在Dynamics 365表单上注册了JavaScript函数:

我的代码工作正常(结果是TypeScript传输):

但如果我试图找到包含我的代码的
script
元素,那么我什么也找不到。我在浏览器控制台(Google Chrome)中运行此代码:

//在主文档内部搜索,子文档位于iFrame中:
让docs=[document];
for(设frameIndex=0;frameIndex

如何找到直接包含我的代码或通过
scr
属性指向它的
script
元素?

事实证明,我的脚本甚至更深(在其他帧中)。我添加了递归检查所有帧的代码,并能够找到我要查找的内容:

/** Find all `script` elements with `src` attribute value that are matched to 
`regexp` parameter. */
function findScripts(regexp) {
    /** The function of recursively extracting documents from frames. */
    const fillDocs = function (docs, frames) {
        for(let frameIndex = 0; frameIndex < frames.length; frameIndex++) {
            const doc = frames[frameIndex].document;
            if(!docs.includes(doc)){
                docs.push(doc);
            }
            fillDocs(docs, frames[frameIndex].frames);
        }
    }

    let docs = [document];
    fillDocs(docs, frames);

    let result = [];

    for(let doc of docs) {
        const tags = doc.getElementsByTagName('script');
        for(let index = 0; index < tags.length; index++) {
            const path = tags[index].getAttribute("src");
            if(path && path.match(regexp)){
                result = [...result, tags[index]];
            }
        }
    }
    return result;
}

// The `findScripts` function using example:
findScripts(/isv_/i).map(n => ({
    type: n.getAttribute("type"), 
    src: n.getAttribute("src"),
    documentTitle: n.ownerDocument.title,
})).forEach(n => console.log(n));
/**查找与匹配的具有`src`属性值的所有`script`元素
`regexp`参数*/
函数findscript(regexp){
/**从帧中递归提取文档的功能*/
常量fillDocs=函数(文档、帧){
for(设frameIndex=0;frameIndex({
类型:n.getAttribute(“类型”),
src:n.getAttribute(“src”),
文档标题:n.ownerDocument.title,
})).forEach(n=>console.log(n));
输出:


事实证明,我的脚本甚至更深(在其他框架中)。我添加了递归检查所有帧的代码,并能够找到我要查找的内容:

/** Find all `script` elements with `src` attribute value that are matched to 
`regexp` parameter. */
function findScripts(regexp) {
    /** The function of recursively extracting documents from frames. */
    const fillDocs = function (docs, frames) {
        for(let frameIndex = 0; frameIndex < frames.length; frameIndex++) {
            const doc = frames[frameIndex].document;
            if(!docs.includes(doc)){
                docs.push(doc);
            }
            fillDocs(docs, frames[frameIndex].frames);
        }
    }

    let docs = [document];
    fillDocs(docs, frames);

    let result = [];

    for(let doc of docs) {
        const tags = doc.getElementsByTagName('script');
        for(let index = 0; index < tags.length; index++) {
            const path = tags[index].getAttribute("src");
            if(path && path.match(regexp)){
                result = [...result, tags[index]];
            }
        }
    }
    return result;
}

// The `findScripts` function using example:
findScripts(/isv_/i).map(n => ({
    type: n.getAttribute("type"), 
    src: n.getAttribute("src"),
    documentTitle: n.ownerDocument.title,
})).forEach(n => console.log(n));
/**查找与匹配的具有`src`属性值的所有`script`元素
`regexp`参数*/
函数findscript(regexp){
/**从帧中递归提取文档的功能*/
常量fillDocs=函数(文档、帧){
for(设frameIndex=0;frameIndex({
类型:n.getAttribute(“类型”),
src:n.getAttribute(“src”),
文档标题:n.ownerDocument.title,
})).forEach(n=>console.log(n));
输出:

/** Find all `script` elements with `src` attribute value that are matched to 
`regexp` parameter. */
function findScripts(regexp) {
    /** The function of recursively extracting documents from frames. */
    const fillDocs = function (docs, frames) {
        for(let frameIndex = 0; frameIndex < frames.length; frameIndex++) {
            const doc = frames[frameIndex].document;
            if(!docs.includes(doc)){
                docs.push(doc);
            }
            fillDocs(docs, frames[frameIndex].frames);
        }
    }

    let docs = [document];
    fillDocs(docs, frames);

    let result = [];

    for(let doc of docs) {
        const tags = doc.getElementsByTagName('script');
        for(let index = 0; index < tags.length; index++) {
            const path = tags[index].getAttribute("src");
            if(path && path.match(regexp)){
                result = [...result, tags[index]];
            }
        }
    }
    return result;
}

// The `findScripts` function using example:
findScripts(/isv_/i).map(n => ({
    type: n.getAttribute("type"), 
    src: n.getAttribute("src"),
    documentTitle: n.ownerDocument.title,
})).forEach(n => console.log(n));