是否可以添加<脚本>添加'_someTag'到iFrame中的URL

Is it possible to add a <script> to the head of a page by adding '?_someTag' to the URL in an iFrame

本文关键字:添加 someTag iFrame 中的 URL 脚本 lt 是否 gt      更新时间:2023-09-26

我正在尝试将脚本添加到加载到iFrame中的页面中。是否可以通过以下方式进行此操作:http://someURl.com?_someTag

"_someTag"将在我的域上的iFrame中将脚本加载到页面(另一个域)的头部?例如,我想像Firebug一样突出页面的某些部分。

检查http://johnverber.com/url.html只是为了看看我正在谈论的页面。

window.location.search就是您想要的。它将返回?_someTag。这是检查存在并注入头部的代码。

if(window.location.search == '?_someTag'){
    $('head').append('<script type="text/javascript" src="path/to/your/file.js"></script>');
}

编辑

哎呀。我刚刚注意到你说你想在iFrame中做这件事。。。我不完全确定你是换了标题,还是我只是因为漫长的一天而神志不清,但这是不可能的。

X域无法做到这一点有安全原因。。。因此不幸的是,的答案是:

这是不可能的

if(location.href.indexOf("blabla")!=-1){
document.getElementById("id_of_the_frame").src = "http://www.google.co.uk";
}