bsh*_*ett 8 windows-desktop-gadgets
我正在尝试在不使用Visual Studio的情况下创建侧边栏小工具.我一直在寻找调试它们的方法,但是一切都说Visual Studio JIT调试器是唯一的方法.
有没有人能够在没有Visual Studio的情况下调试侧边栏小工具?
And*_*y E 16
多年来,我没有使用Visual Studio来处理小工具.有几种方法可以在没有它的情况下调试小工具,只是没有那么广泛.例如,如果没有debugger;
附加到进程的适当调试器,则无法使用该命令.你可以做的是使用像DebugView这样的程序来捕获System.Debug.outputString()
方法输出的消息:
function test ()
{
System.Debug.outputString("Hello, I'm a debug message");
}
Run Code Online (Sandbox Code Playgroud)
这允许您在代码的某些阶段输出变量转储和其他有用的信息,因此您可以随意跟踪它.
作为替代方案,您可以使用滚动自己的调试/脚本暂停消息window.prompt()
.alert()
已被禁用的小工具confirm()
被覆盖以始终返回true,但他们必须忽略prompt()
.
function test ()
{
// execute some code
window.prompt(someVarToOutput, JSON.stringify(someObjectToExamine));
// execute some more code
}
Run Code Online (Sandbox Code Playgroud)
JSON.stringify()
如果要在代码执行期间检查对象的状态,该方法确实有帮助.
而不是window.prompt
,您也可以使用VBScript MsgBox()
函数:
window.execScript( //- Add MsgBox functionality for displaying error messages
'Function vbsMsgBox (prompt, buttons, title)\r\n'
+ ' vbsMsgBox = MsgBox(prompt, buttons, title)\r\n'
+ 'End Function', "vbscript"
);
vbsMsgBox("Some output message", 16, "Your Gadget Name");
Run Code Online (Sandbox Code Playgroud)
最后,您可以使用事件处理程序捕获脚本中的所有错误window.onerror
.
function window.onerror (msg, file, line)
{
// Using MsgBox
var ErrorMsg = 'An error has occurred'+(line&&file?' in '+file+' on line '+line:'')+'. The message returned was:\r\n\r\n'+ msg + '\r\n\r\nIf the error persists, please report it.';
vbsMsgBox(ErrorMsg, 16, "Your Gadget Name");
// Using System.Debug.outputString
System.Debug.outputString(line+": "+msg);
// Using window.prompt
window.prompt(file+": "+line, msg);
// Cancel the default action
return true;
}
Run Code Online (Sandbox Code Playgroud)
该window.onerror
事件甚至允许您输出发生错误的行号和文件(仅适用于IE8).
祝你好运调试,并且在发布你的小工具时记得不要离开任何window.prompts或MsgBoxes!
在Windows 7中添加了一个新的注册表项,它在运行时在给定的PC上显示脚本错误:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Sidebar]
"ShowScriptErrors"=dword:00000001
Run Code Online (Sandbox Code Playgroud)
设置该值后,您将看到脚本错误发生时的对话框.
归档时间: |
|
查看次数: |
4565 次 |
最近记录: |