Monday, March 4, 2013

SharePoint dynamically load content into an iframe

For some weird reason I have had this fascination with trying to use the iFrame with a CEWP and some javascript to basically load in other content found within the site collection into a static page. I guess one of the things I really don't like about SharePoint is all the button clicking required to use it on a daily basis, also I have to often find a no code type solution, so this will be ideal for a quick prototype.

This time I finally succeeded in getting this to work pretty close to the way I wanted it to. This working examples uses a few things, I have a site that has several dashboard type sites under it. Each dashboard sub site will have a Pages Library and about 10 web part pages in it. These pages are standard web part pages and as such can be used for showing a set of related bits of data on my main page on as their own independent pages, reports, or other generalized groups of information.

My goal was to have the main page for each sub site have a either a HTML Form Web Part or a  Content Editor Web Part on it. The CEWP will point back to a centrally managed script file called dashboardIframe.txt that I stored in the root site in a document library called scripts and set domain users to have read permissions. To get things going I am going to use the HTML Form Web Part and edit the code right on the page.

The script has a set of buttons with pre-defined urls, that when clicked with run a bit of javascript that basically dynamically sets the src attribute of the iframe and forces it to reload, giving us the additional content we would like to display.

?isdlg=1 needs to be appended to each url to hide the ribbon just like when the modal dialog window opens.
My example below loads the main page from each one of my dashboard sub sites, there is only the description of the site and its name showing right now on each page.
Each button click loads a page from a  different SharePoint site into our iframe
This has potential to be pretty useful for when you have too much stuff on one page and you want to break it apart and centralize where you go to see it or a wide range of content from pretty much anywhere in  your portal. This works great for displaying views of libraries and lists too, plus you only load what your users want to see.

No comments: