Question

I have a promoted links webpart that I need to display only if a particular text string is displayed in another webpart on the same page. I can successfully capture the text string to a variable but my links webpart isn't being hidden.

Here is my code so far:

<script type="text/javascript">
var ProjectPhase = document.querySelector("table[summary='Project Info Log']").innerText.match(/Phase [1-9]/g)[0]

if (ProjectPhase == 'Phase 1')
{document.getElementById("MSOZoneCell_WebPartWPQ6").style.display = 'none'}

</script>
Était-ce utile?

La solution

A few things to check...

The web part is still #6 on the page. ("MSOZoneCell_WebPartWPQ6")

What happens if you type "document.getElementById("MSOZoneCell_WebPartWPQ6").style.display = 'none'" into the browser's Console?

The Summary text contains more than the text you are testing for. Extra spaces, the list's title, etc. summary='Project Info Log' Change to this to a "contains" test.

You regular expression will also match "Phase 11"

Autres conseils

The following code for your reference,add the code into a script editor web part in site page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var projectPhase=$("table[summary='Project Info Log']").text();
    if(projectPhase.indexOf("Phase 1")!=-1){
        $("#MSOZoneCell_WebPartWPQ6").hide();
    }
});
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top