[In nutshell, how to display a Page Viewer Web Part with 100% height of the available screen estate.]
A co-worker of mine was working with a customer and he was trying to put a page viewer web part in a Web Part page in MOSS to display his web site. On the whole of page, only 1 Page Viewer web part was there but was still sticking to it's default zone height and not expanding to 100% of height available.
I tried playing around with the settings, but default Page Viewer Web Part can only have absolute "height" parameter and cannot take height in percentage (I wanted to give 100% to make sure it scales to small and large screen sizes).
Then came in the tried and trusted HTML DOM. I took hold of my Developer Toolbar in IE and started digging into the DOM of the page and trying to figure out what all properties can be played along. Tried just changing the height of IFrame which renders the "outside" page, but no luck. Through hit 'n trial found that all the Table tags in the hierarchy need to be changed to 100% height. So came up with the JScript code to do it automatically every time the page is loaded. The JScript code below was added to a Content Editor web part.
The steps:
<script language="javascript"> 1: 2: var a = MSO_ContentTable.getElementsByTagName("table"); 3: 4: MSO_ContentTable.setAttribute("height","100%"); 5: 6: for(i=0;i<a.length;i++) 7: { 8: 9: a[i].setAttribute("height","100%"); 10: } 11: 12: var z = document.getElementsByTagName("div"); 13: 14: 15: for(i=0;i<z.length;i++) 16: { 17: if(z[i].id.indexOf("WebPartWPQ",0) >=0 ) 18: { 19: if(z[i].hasChildNodes()) 20: { 21: if(z[i].firstChild.nodeName.toUpperCase() == "IFRAME") 22: { 23: z[i].firstChild.setAttribute("height","100%"); 24: } 25: } 26: } 27: }</script>
1:
2: var a = MSO_ContentTable.getElementsByTagName("table");
3:
4: MSO_ContentTable.setAttribute("height","100%");
5:
6: for(i=0;i<a.length;i++)
7: {
8:
9: a[i].setAttribute("height","100%");
10: }
11:
12: var z = document.getElementsByTagName("div");
13:
14:
15: for(i=0;i<z.length;i++)
16: {
17: if(z[i].id.indexOf("WebPartWPQ",0) >=0 )
18: {
19: if(z[i].hasChildNodes())
20: {
21: if(z[i].firstChild.nodeName.toUpperCase() == "IFRAME")
22: {
23: z[i].firstChild.setAttribute("height","100%");
24: }
25: }
26: }
27: }
You can actually mark Content Editor Web Part as "Hideen" (Tool Pane -> Layout -> Hidden) and it would not show up on your page but still execute the JScript code and get your Page Viewer Web Part as a full height control.
Happy Coding...
-Manpreet
This worked perfect!!!
Much better than anything else I found!
Thanks!!
Hi,
I wanted to know if,
1. We can view a section/portlet of an external portal/Web Application?
Using Page Viewer Web part we get a full view of the web application but I would like to ONLY view a section/portlet of the external web page.
2. How to achieve session aware Page viewer web part
Regards,
Jay
Hi Jay,
Page Viewer webpart is just an IFrame to display an external page. If you want to use a Portlet provider, you can look into WSRP Consumer Web Part available in SharePoint.
As stated earlier, Page Viewer is just an IFrame, so it is not session aware. If you want a session aware webpart or want to screen scrap a part of a webpage, you would need to write your own custom webpart.
Regards
Manpreet
Hi Manpreet,
Very impressive. This worked perfectly for me. I used the Page Viewer Web Part to view a report from MS SQL Report Services. I was ready to begin programming a custom web part, but this neat little trick saved me a lot of time.
Thanks
Amel
Thanks Manpreet!!! Excellent solution
For me, I had to enter the Content Editor web part UNDER the Page Viewer part (instead of above) for this work..
Best solution by far. No widgety code changes to legacy web applications, etc.
Thank you SO much!
Thanks for the solution - Do you know if it is possible to do this with a Page Viewer webpart & Content Editor webpart in a wiki page?
It doesn't seem to work for me?
Thanks,
Jonathan
Thanks Manpreet,
Do you know if we need to do anything different to use your solution with the Content Editor webpart+ Page Viewer webpart in the webpart zone of a Wiki page?
Thanks again,
Hi Jonathan,
This is a very specific code for the OOTB page layout (Full Page, Vertical). For using it on any of the other pages, you would need to check where is your exact Page Viewer embedded in the HTML.
Then you would need to write/modify the code accordingly. For Wiki pages, the HTML structure would be different and exact HTML code will not work.
You can use IE Developer Toolbar to find out the exact layout of your webpart and fine tune the code for it.
Let me know if there is anything more that I can help with.
This is great! Just one question. I noticed this makes my single web part space down quite a bit from the top of the window. Any thoughts on how to get rid of the white space at the top?
I didn't realize how old this post was, but for anyone who had the same question I did all you have to do is set the chrome state to border only and all of the white space above your web part will be gone.
Is there any way to add this to a one column layout? I have tried modifying the code to work with the page and cannot get the tags correct. It the one column layout will not work, then how would you add this the web part page that is created here to a main site page? Thanks
Is there any way to add this to a one column layout? I have tried modifying the code to work with the page and cannot get the tags correct. If the one column layout will not work, then how would you add this the web part page that is created here to a main site page? Thanks
I don't understand this line:
var a = MSO_ContentTable.getElementsByTagName("table");
"MSO_ContentTable" is never defined, so this doesn't make sense.
Janette: You would need to study the DOM for the exact page where you are adding the webpart and trace it down from there and set the height of each container object to 100%. That would get you going.