从Sharepoint Online中的快速启动打开新窗口 //向_spBodyOnLoadFunctionNames数组添加一个条目 //这样我们的函数将在pageLoad事件上运行 _spBodyOnLoadFunctionNames.push(“重写链接”); 函数重写链接(){ //创建一个数组来存储页面中的所有锚元素 var archors=document.getElementsByTagName(“a”); //在数组中循环 对于(var x=0;x0){ //存储此锚元素的HTML oldText=archors[x].outerHTML; //重写URL以删除测试文本并添加目标 newText=oldText.replace(/#openinnewwindow/,'“target=“_blank”); //将HTML写回浏览器 锚[x].outerHTML=newText; } } }
我把这段代码放在settle.master文件中,然后在quick launch中编辑链接时,我把#openinnewindow放在网站地址之后。在“尝试链接”上,这将打开网站。我的问题是当我保存它时。然后单击在新窗口中未打开的链接。你知道为什么会这样吗 我意识到,为了让这段代码正常工作,我需要启用发布功能 代码中的注释为+1。您是否检查了生成的HTML?脚本是否正常运行及其工作?从Sharepoint Online中的快速启动打开新窗口 //向_spBodyOnLoadFunctionNames数组添加一个条目 //这样我们的函数将在pageLoad事件上运行 _spBodyOnLoadFunctionNames.push(“重写链接”); 函数重写链接(){ //创建一个数组来存储页面中的所有锚元素 var archors=document.getElementsByTagName(“a”); //在数组中循环 对于(var x=0;x0){ //存储此锚元素的HTML oldText=archors[x].outerHTML; //重写URL以删除测试文本并添加目标 newText=oldText.replace(/#openinnewwindow/,'“target=“_blank”); //将HTML写回浏览器 锚[x].outerHTML=newText; } } },sharepoint,sharepoint-online,Sharepoint,Sharepoint Online,我把这段代码放在settle.master文件中,然后在quick launch中编辑链接时,我把#openinnewindow放在网站地址之后。在“尝试链接”上,这将打开网站。我的问题是当我保存它时。然后单击在新窗口中未打开的链接。你知道为什么会这样吗 我意识到,为了让这段代码正常工作,我需要启用发布功能 代码中的注释为+1。您是否检查了生成的HTML?脚本是否正常运行及其工作? <script type="text/javascript"> //add an entry t
<script type="text/javascript">
//add an entry to the _spBodyOnLoadFunctionNames array
//so that our function will run on the pageLoad event
_spBodyOnLoadFunctionNames.push("rewriteLinks");
function rewriteLinks() {
//create an array to store all the anchor elements in the page
var anchors = document.getElementsByTagName("a");
//loop through the array
for (var x=0; x<anchors.length; x++) {
//does this anchor element contain #openinnewwindow?
if (anchors[x].outerHTML.indexOf('#openinnewwindow')>0) {
//store the HTML for this anchor element
oldText = anchors[x].outerHTML;
//rewrite the URL to remove our test text and add a target instead
newText = oldText.replace(/#openinnewwindow/,'" target="_blank');
//write the HTML back to the browser
anchors[x].outerHTML = newText;
}
}
}
</script>