2
<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>

我有这段代码,之前我把它放在了 seattle.master 文件中然后在快速启动时,当我编辑链接时,我把#openinnewwindow 放在网站地址之后。在“尝试链接”上,这会打开正确的网站。我的问题是当我保存它时。然后单击它不会在新窗口中打开的链接。任何想法为什么会发生这种情况?

4

1 回答 1

1

我意识到要让这段代码工作,我需要启用发布。

于 2014-04-28T15:26:36.580 回答