Open link in SP Dialog from Global Navigation / Quick launch

Requirement

Building on my previous post about opening a link in a SP dialog window (similar to lightbox), we decided to make it so that clicking on the link under the quick launch or top navigational bar would open the page immediately in a SP dialog box. This is not possible out of the box, as SharePoint does not allow javascript in the links under the top navigation / quick launch. Here is our work around using Jquery/javascript.

The benefit of this for us is that users can now open the staff directory from anywhere on the site collection without leaving their current page as long as they have access to the top navigational bar.

Solution

This solution uses Jquery. Change the bits in bold to meet your requirements. If you want this to work on every page in the site collection, you will need to add this script to the master page. This script will:

  1. Load the Jquery library from your SharePoint site collection.
  2. Check if the link being clicked leads to a page called ‘staffdir.aspx’.
  3. Open the link to the page (http://path/to/staffdir.aspx) specified under in a SP Modal Dialog.

<script type=”text/javascript” src=”http://path/to/jquerylibrary/jquery-1.4.4.min.js”></script> <script type=”text/javascript”> $(document).ready(function(){ $(“a[href$=’staffdir.aspx‘]”).click(function() { SP.UI.ModalDialog.showModalDialog({ url: “http://path/to/staffdir.aspx“, title: “Staff Directory“, allowMaximize: true, showClose: true, width: 1200, height: 768, dialogReturnValueCallback: function (dialogResult, returnValue) {}});   return false; }); }); </script>

 

Tags: , ,

No comments yet.

Leave a Reply

%d bloggers like this: