ode*_*dbd 26 javascript fiddler
我正在考虑将Fiddler用于以下目的......
我有一个基于JavaScript的服务,我想向潜在客户展示.为了向他们展示如果他们安装(包括)我的脚本,他们的网站会是什么样子,我想在我的PC上设置Fiddler,以便在获取客户的网站时,
<script type="text/JavaScript" src="myscript.js"></script>
Run Code Online (Sandbox Code Playgroud)
该行将包含在HTML <head>部分中.
这可以用Fiddler轻松完成吗?有人能指出我在哪里可以找到涵盖的文件,如果是的话?
谢谢!
---- ----更新
目前我已经使用BHO将我的脚本添加到页面中.我在onDocumentComplete上使用execScript()来运行一段简单的JavaScript,它将我需要的.js文件附加到页面上.但EricLaw的指针和抖动的答案似乎是一种更完整(和优雅)的方式来做我需要的方式.
如果有人有兴趣,我可以在这里上传BHO代码.-谢谢!
jit*_*ter 30
打开提琴手 - >菜单规则 - >自定义规则(或按Ctrl + R)
该CustomRule.js文件打开.向下滚动,直到找到该行
static function OnBeforeResponse(oSession: Session)
Run Code Online (Sandbox Code Playgroud)
这是您的代码所在.在这里,您可以在浏览器看到之前更改服务器响应.
下面的代码示例演示了如何包含一个自定义的jQuery代码片段,该代码将水平菜单中的Unanswered链接替换为一个链接,该链接用作未答复的jQuery问题的简短链接
我首先向您展示我想要包含的jQuery代码
<script type='text/javascript'>
$(function() {
var newLink = '<a href="/unanswered/tagged/jquery">Unanswered jQuery</a>';
$('div#hmenus div.nav:first ul li:last a').replaceWith(newLink);
});
</script>
Run Code Online (Sandbox Code Playgroud)
现在是fiddler代码(基于CustomRules.js中的代码和来自FiddlerScript CookBook的代码示例)
//is it a html-response and is it from stackoverflow.com
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html") &&
oSession.HostnameIs("stackoverflow.com")) {
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Match the jQuery script tag
var oRegEx = /(<script[^>]*jquery.min.js"><\/script>)/gi;
// replace the script tag withitself (no change) + append custom script tag
oBody = oBody.replace(oRegEx, "$1<script type='text/javascript'>$(function() {$('div#hmenus div.nav:first ul li:last a').replaceWith('<a href=\"/unanswered/tagged/jquery\">Unanswered jQuery</a>');})</script>");
// Set the response body to the changed body string
oSession.utilSetResponseBody(oBody);
}
Run Code Online (Sandbox Code Playgroud)
结果如下所示
修改后的stackoverflow.com http://img269.imageshack.us/img269/570/clipboard01ym.jpg
我认为你现在应该能够自己解决一段符合你问题的代码.
例
// Match the head end
var oRegEx = /(<\/head>)/gi;
// replace with new script
oBody = oBody.replace(oRegEx, "<script type='text/javascript' src='http://url/myscript.js'></script>$1");
Run Code Online (Sandbox Code Playgroud)
如果你使用 jQuery,你可以动态添加 js。我可能认为您可以有一种方法可以根据某些查询参数包含/排除您的脚本。这就是将 JS 包含在 jQuery 中的方式
$.getScript('someScript.js',function(){
//Do something here after your script loads
});
Run Code Online (Sandbox Code Playgroud)