question

ChristopheVandeput-7716 avatar image
0 Votes"
ChristopheVandeput-7716 asked ·

document.title value for modern SharePoint pages

Hi,

I have some JavaScript injected on my modern SPPages.
JavaScript file hosted in the MasterPageGallery and injected by Application Customizer (SPFx).

In the JavaScript code I want to use document.title to log some data to an external system at page loading.
Now I see that my external system (very) often receives the title of previous page. So it seems that document.title is not updated yet.
Is this due to partial loading of page components of modern pages?

Any idea's?

Kind Regards


Vandeput

office-sharepoint-online
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ChristopheVandeput-7716 avatar image
0 Votes"
ChristopheVandeput-7716 answered ·

Hi, I did some testing.
And my issue is due to the partial page loading mechanism of Modern SharePoint pages.
In some cases the document.title isn't updated correctly when I need it, it still the old value. If you wait few moment, it will be updated with the new version.

So I need to do this in my Application Customizer itself.
Check to following post for more info : https://blog.velingeorgiev.com/page-hit-when-SPA-page-transitioning-modern-sharepoint-sites


· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ChristopheVandeput-7716 ,

Great hear the partial page loading issue is resolved by Window.SetTimeOut and Thanks for your sharing.

I suggest you can acccept your own reply as answer so that it could also help others who have the similiar question in the forum.

Thanks
Best Regards

0 Votes 0 ·
Jerryzy-MSFT avatar image
0 Votes"
Jerryzy-MSFT answered ·

Hi @ChristopheVandeput-7716 ,

document.title should be updated when the modern page title changed, I tested with application customizer inject with a simplest JavaScript file like this, just like this:

73685-snipaste-2021-03-03-15-27-54.png

Then inject in Application Customizer:

73580-snipaste-2021-03-03-15-28-58.png

After deploying to App Catalog, it's working as expected for the document.title value update:

Previous:

73711-snipaste-2021-03-03-15-30-22.png

Updated:

73650-snipaste-2021-03-03-15-31-03.png

Thanks
Best Regards


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ChristopheVandeput-7716 avatar image
0 Votes"
ChristopheVandeput-7716 answered ·

I will try to simulate like you did with an alert. I will update when I have more info.

· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sure. will wait for your information :)

0 Votes 0 ·

Hi @ChristopheVadeput-7716,

Is there any update ? Did you try to test with alert like the answer above ? And if it work ?

Thanks
Best Regards

0 Votes 0 ·