Cloud Decoded

Lets understand cloud better…

  • Home
  • About
  • Contact
  • Disclaimer & Policies
Menu

SharePoint

Playing with SharePoint Pages Dynamic Div IDs

May 1, 2017 No Comments
Hey Guys,
I am sure there are many other ways, you might have achieved similar results, but dynamic div ids in SharePage pages give a hard time to many developers.Like most other people, developers love certainty, but SharePoint pages may generate 2 different div ids even for same page, when accessed by 2 different users, because of  different permissions.I recently had a requirement to put a direct link to users’ my site document library in the my site host page. It’s a SharePoint 2016 environment, but they were not yet ready to go for OneDrive interface and decided to stick to old my site profile page.

This is how a default left nav (with some css) appears in old style profile landing page

with Apps pointing to “Site Contents” page of logged in user’s my site. The customer wanted to replace this Apps with “My Documents” pointing directly to user’s Document Library.

I know the default behaviour of OneDrive redirection is to show user’s document library view on landing page, but what can I say, customer wasn’t ready for OneDrive yet. And since this requirement was for the profile landing page only, no master page changes or JS injection stuffs… just simple javascript added to the page in a script editor web part.

But the problem, the Div id of this left nav kept on changing, sometimes it was zz10_RootAspMenu,then changed to  zz11_RootAspMenu and even zz12_RootAspMenu. You got the idea that simple getelementbyid wouldn’t have worked.

So, here we go…

      //Fix My Site link in Left Nav  
      var itemFoundAtIndex = -1;  
      //Ensure the link is changed only when user is viewing his/her prfile  
      if(window.location.href.indexOf("Person.aspx?accountname=") == -1)  
      {  
           //Get the left nav element by class name  
           menuElement = document.getElementsByClassName("root ms-core-listMenu-root static");  
           //loop through all the element items  
           for(i=0;i <=menuElement.length;i++)  
           {  
                //loop through all the children  
                for(j=0;j <= menuElement[i].children.length;j++)  
                {  
                     oldLink = menuElement[i].children[j];  
                     //Find the one to replace  
                     if(oldLink.innerText.indexOf("Apps") != -1)  
                     {  
                          oldLink = oldLink.innerHTML.replace("/_layouts/15/viewlsts.aspx", "/Documents/Forms/My Documents.aspx");  
                          newLink = oldLink.replace(/Apps/g, "My Documents");  
                          menuElement[i].children[j].innerHTML=newLink;  
                          itemFoundAtIndex = j;  
                          break;  
                     }  
                }  
                if(itemFoundAtIndex >= 0)  
                {  
                     break;  
                }  
           }  

Even though, I am sure, it’s not the best way to achieve this, this works 🙂
Let me know if you found a better way t play with such dynamic divs.

Cheers,
Anupam

CustomizationDivDynamic DivJavasScriptPagesProfileSharePointUser Profile
Previous Post Next Post
Anupam Shrivastava

Anupam Shrivastava

Anupam Shrivastava, a learner, explorer, traveler and tech enthusiast. New technologies drive me and cloud is where we live now. So, lets try to make the world better for our fellow cloudizens :)

You may also like

July 17, 2017
BotWithSP-Featured

Integrate Azure Chat Bot with SharePoint

May 20, 2017
Multiple NIC

How to ensure SharePoint performance during SQL backups

March 19, 2018
File Share Featured

Migrate Files Shares to Microsoft Cloud

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Author

Anupam

Anupam Shrivastava, a learner, explorer, traveler and tech enthusiast. New technologies drive me and cloud is where we live now. So, lets try to make the world better for our fellow cloudizens :)

Recent Posts

  • Docker container runtime transition to containerd runtime – Fix Sitecore containers
  • Use Azure Devops Pipelines to Deploy Applications within Closed Networks
  • Sitecore Production Environment on Azure Kubernetes Services – Part 4 (Putting everything together with Azure Devops)
  • Automate Office 365 Health Status Monitoring with Power Automate Using Service Communications Graph API
  • AUTOMATE OFFICE 365 HEALTH STATUS MONITORING USING OFFICE 365 SERVICE COMMUNICATIONS GRAPH API

Recent Comments

  • Phu Huynh on Send Meeting Invites to SharePoint Online Calendar
  • andreea on Power of Power Automate and a Big Limitation!
  • Gaurav Singh on SharePoint Crawl Error- Processing this item failed because of a timeout
  • Eddie Cortez on Send Documents by Email to SharePoint Online
  • gam on Deploy Solutions to On-Premise Servers using Azure DevOps

Categories

  • ADFS
  • Analytics
  • Azure
  • Azure Chatbot
  • Azure DevOps
  • Enterprise Search
  • Flow
  • Kubernetes
  • MS Teams
  • Office 365
  • OneDrive
  • Power Automate
  • PowerApps
  • SharePoint
  • SharePoint Online
  • SharePoint Online
  • Sitecore
  • Tools
  • Visual Studio

Archives

  • May 2023
  • October 2022
  • March 2022
  • January 2022
  • October 2021
  • September 2021
  • August 2021
  • May 2021
  • March 2021
  • February 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • November 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • April 2019
  • March 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • November 2017
  • October 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • September 2016
  • October 2015
  • May 2015
  • February 2015
  • January 2015
  • November 2014
  • October 2014
  • April 2013
  • October 2012
  • June 2012
  • February 2010
  • October 2009
  • August 2007

Popular Tags

ADFS 3.0 AKS Analytics Apps Architecture Automation Azure Azure AD Azure bot Azure EndPoints Chat Chat Bot Chatbot Chrome Customization Enterprise Search External Access FAST FAST Search 2010 Flow Forms Flow Groups Guest Health Kubernetes Machine Learning Microsoft Flow Migration Monitoring O365 Office 365 OneDrive OneDrive for Business Performance PowerApps PowerShell Redirection Search SharePoint SharePoint 2010 SharePoint 2013 SharePoint 2016 SharePoint Online Skype Teams
  • Home
  • About
  • Contact
  • Disclaimer & Policies

Cloud Decoded

Lets understand cloud better…