代码之家  ›  专栏  ›  技术社区  ›  Marian Polacek

Sharepoint、ajax和页面标题

  •  3
  • Marian Polacek  · 技术社区  · 16 年前

    但我们需要某种方式为所有页面提供sommon标题,因此标题如下所示: 我的默认标题-当前页面标题

    有什么办法解决这个问题吗?

    5 回复  |  直到 16 年前
        1
  •  5
  •   James    15 年前

    我想我会分享我对这个讨厌问题的解决方案。我最后做的是扔掉我在下面拼凑的这个方便的小脚本。您可以将其放入自定义页面布局或自定义母版页中。它的工作原理是连接一个AJAX事件处理程序,在AJAX更改标题之前获取标题,然后使用上面的Darpy代码重新应用标题。这允许始终显示正确的页面标题。

    <script type="text/javascript">
    
    // This script is to fix the issue where AJAX causes SharePoint 
    // publishing pages to sometimes make the page title something 
    // whacky. 
    var app = Sys.Application;
    var origTitle = "";
    app.add_init(SPCustomAppnInit);
    
    
    function SPCustomAppnInit(sender) {
      origTitle = document.title; // grab the original title.
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      if (!prm.get_isInAsyncPostBack())
      {
     prm.add_pageLoaded(SPCustomPageLoaded); // wire up loaded handler.
      }
    }
    
    function SPCustomPageLoaded(sender, args) {
    
     document.title = origTitle; // put the original title back on the document.
    }
    
    <script>
    
        2
  •  3
  •   user26888    16 年前

    当硬编码无法实现时,我使用javascript更改页面标题:document.title=“title fixup here”;

    据说微软计划在下一个sharepoint版本中解决这个问题。

        3
  •  3
  •   Steve J    14 年前

    检查您的母版页。如果它有这样的东西:

    <title>
    <sharepointwebcontrols:listitemproperty property="Title" ...>
    </title>
    

    …然后将其更改为全部在一行上,如下所示:

    <title><sharepointwebcontrols:listitemproperty property="Title" ...></title>
    

        4
  •  0
  •   Marian Polacek    16 年前

    这看起来像是纯sharepoint的问题。此外,似乎只有基于发布页面布局的网站受到影响。

    我调试了我们的网页部件,但没有一个会玩网页标题。我建议不要使用发布或只是不要在标题中使用任何控件。

        5
  •  0
  •   sjngm quinti    13 年前

    <script type="text/javascript"> 
    
    // This script is to fix the issue where AJAX causes SharePoint  
    // publishing pages to sometimes make the page title something  
    // whacky.  
    var app = Sys.Application; 
    var origTitle = ""; 
    app.add_init(SPCustomAppnInit); 
    
    
    function SPCustomAppnInit(sender) { 
      origTitle = document.title; // grab the original title. 
      var prm = Sys.WebForms.PageRequestManager.getInstance(); 
      if (!prm.get_isInAsyncPostBack()) 
      { 
     prm.add_pageLoaded(SPCustomPageLoaded); // wire up loaded handler. 
      } 
    } 
    
    function SPCustomPageLoaded(sender, args) { 
    
     document.title = origTitle; // put the original title back on the document. 
    } 
    
    </script> 
    

    非常感谢

    推荐文章