Sharepoint-如何在Outlook for Test中生成脚本错误 [英] Sharepoint - How to Generate a Scripting Error in Outlook for Test
问题描述
你好
我正在尝试在Sharepoint上测试错误抑制,但是遇到了一些麻烦.
这是我的过程:
在一个相对简单的网站上(它包含的所有内容都是有色div),我添加了以下脚本:
On a relatively plain website (all it contains is a colored-in div), I added this script:
<script>
var x[] = 0;
var err = 10/x;
alert(err);
</script>
将Outlook主页设置为此站点时,我看到此错误:
When setting my Outlook homepage to this site, I see this error:
我还有以下脚本,可禁止显示此消息(将其添加到我的代码中时,不会出现错误消息):
I also have the following script, which suppresses this message (when adding this to my code, the error message doesn't appear):
<script type="text/javascript">
window.onerror = function(message, url, lineNumber) {
// code to execute on an error
return true; // prevents browser error messages
};
</script>
我想在我的Sharepoint网站上测试此脚本,但是当我在Sharepoint主页上嵌入上述会引发错误的代码并在Outlook中打开该页面时,我没有看到任何错误消息.
I want to test this script out on my Sharepoint site, but when I embed the above, error-inducing code onto my Sharepoint homepage and open the page in Outlook, I am not seeing any error messages.
我通过以下方式添加了代码:
I added the code in the following ways:
1 - Page > Edit > Edit Source > Added the code to the top
2 - Page > Edit > Embed Code > Added the code to various areas of the page
这两种方法都不起作用,第一个实际上产生了消息 告诉我应该使用embed函数,但该方法似乎也不起作用!
我需要在Sharepoint页面上生成此错误,以便我可以检查**该错误抑制脚本是否实际执行了预期的操作. **任何人都可以想到这里可能出了什么问题吗?
非常感谢您的帮助!
推荐答案
This is apparently a known issue in Sharepoint, and can be resolved by using the following function:
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
//your code goes here...
});
出于上述测试的目的,我能够产生以下错误:
For the purposes of the above test, I was able to generate an error with the following:
<script language='javascript'>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
var x[] = 0;
var err = 10/x;
alert(err);
});
</script>
并添加以下内容可消除错误:
And adding the below suppressed the errors:
<script language='javascript'>
window.onerror = function(message, url, lineNumber) {
return true;
};
</script>
请注意,这仅在将2位代码添加到各自独立的<script>
标签中后才有效.我还必须在标签中添加language='javascript'
才能起作用.
Note that this only worked for me after adding the 2 bits of code in their own, seperate <script>
tags. I also had to add language='javascript'
to the tags before it would work.
我通过嵌入一些新代码来添加代码,并将两个脚本标签都添加到该Web部件中.因为我能够产生错误消息,所以我也能够证明错误抑制方法有效.
I added the code by embedding some new code, and adding both of the script tags to that web part. Because I was able to produce the error message, I was also able to prove that the error-suppression method worked.
这篇关于Sharepoint-如何在Outlook for Test中生成脚本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!