Sharepoint, ajax and page title

左心房为你撑大大i 提交于 2019-12-04 13:04:05

I don't have a reference to the newsgroup post, but this is a known problem with publishing pages, as drax mentioned. The workaround I have used in the past is to hard code the title on the page - the metadata title being lost is part of the bug.

When hardcoding wasn't possible, I have used javascript to change the page title: document.title = "title fixup here";

Supposedly microsoft plans to fix this problem in the next sharepoint release.

I thought I would share my solution to this pesky issue. What I ended up doing was throwing down this handy little script I put put together below. You can put this in your custom page layout or custom master page. It works by wiring up an AJAX event handler to grab the title before AJAX changes it and then re-applies it using Darpy's code above. This allows for the proper page title to always show.

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

I realize that this has been answered already, but I'm going to throw in my $.02. It appears that the problem manifests itself because of two conditions: (1) using an AJAX asynchronous postback and (2) having a multi-line <title> element in the <head> of the page.

Check your master page. If it has something along the lines of this:

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

...then change it to be all on one line, like so:

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

Problem solved. No javascript required.

this looks like pure sharepoint's problem..also it looks like just sites based on publishing page layout are affected.

I debugged response in firebug and for some reason it returns setting for page title, so response from server contains not just update panel information, but also empty page title.

I debugged our webparts and none of them plays with page title. I would suggest not to use publishing or just not use any controls inside title.

We are currently working on this issue in company i work for, so i'll upload uour findings when we figure out something.

Miss ZerOne

Adding the following @ the begining of my webpart user control Fixed the issue

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

thanks ALOT :D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!