2

I have added a Page Viewer Web Part to a default.aspx page and included the url to DispForm.aspx?ID=1 for a list.

However, I don't want the ribbon for DispForm to be displayed in the PVWP.

If I add a Script Editor Web Part with the following CSS, both the Ribbon for DispForm.aspx (within the PVWP) and the Ribbon for Default.aspx is removed.

<style type="text/css">
#s4-ribbonrow {
    display: none;
}
</style>

Does anyone have any advice on how to remove only the ribbon within the Page Viewer web Part?

1

Edit your DispForm.aspx and add content editor web part (or script editor).

Put the following script inside:

_spBodyOnLoadFunctions.push(function(){
    if(getParameterByName('hide')){
      var ribbon = document.getElementById('s4-ribbonrow');
      ribbon.style.display = 'none'; 
    }
});

function getParameterByName(name, url) {
    if (!url) {
      url = window.location.href;
    }
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
} 

In your page viewer put following url: DispForm.aspx?ID=1&IsDlg=1&hide=1

How does it work

The script on DispForm watches if url contains hide query param. If so, ribbon is hided. Javascript-only solution, no jquery required.

  • Thank you very much! The suffix to the url and the script editor on Dispform.aspx solved the problem. Now the page viewer looks exactly like I wanted it. – Jenny Fergéus Dec 5 '16 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.