Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to set up on iframe on a SharePoint 2007 page that will show the most current project report uploaded to a document library. Here is my code, inserted into the page in the source of a Content Editor Web Part. I will explain how it works below

<script type="text/javascript" language="javascript">
 function CurrentReport()
 {
      var link = $(".ms-vb-icon:first a").attr("href");
      return "https://intra.sse.gov.on.ca" + link;  
 }

 $(document).ready(function(){
      $("#EPMReport").attr("src",CurrentReport()); 
 });

</script>

<iframe class="EPMReport" id="EPMReport" height="605" width="795" src=""/>

The way it works is that the page has a list view web part of the document library on it sorted by date to get the newest at the top. The CurrentReport function searchs through the page to find and return the link to the first item of the document library. Then the iframe src is set by calling the function CurrentReport(). Everything works and the current report is shown in the iframe but there is two errors on the page caused. Error message for both is

Message: Object expected
Line: 483
Char: 2
Code: 0

Both errors say the same thing and I can't find any code on line 483 would be causing the problem.

In the Content Editor web part I have tried putting the iframe code above the javascript and it then doesn't work at all, no report is shown. Any ideas would be great. Thanks in advance for any help.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Why are you combining jQuery and old-fashioned IE-only DOM code?

Try this:

<script type="text/javascript" language="javascript">
 function CurrentReport()
 {
      var link = $(".ms-vb-icon:first a").attr("href");
      return "https://intra.sse.gov.on.ca" + link;  
 }

 $(document).ready(function(){
      $("#EPMReport").attr("src",CurrentReport());
 });

</script>

<iframe class="EPMReport" id="EPMReport" height="605" width="795" src=""></iframe>
share|improve this answer
    
Changed the code to be all jQuery. Still getting the errors that both say the same thing. –  Michael Nov 28 '11 at 20:08
2  
This might be pedantic, but try the iframe tag that's not self-closing. See edit. –  James Love Nov 28 '11 at 20:20
    
That got it. Don't know why but it did. Thanks a ton James –  Michael Nov 28 '11 at 20:41
    
Some DOM stuff doesn't like self-closing tags, which is why you always see <script></script> for loading javascript files. –  James Love Nov 28 '11 at 20:49
    
This saved me for sure. The iframe self-closing thing is quite the gotcha –  jle Nov 13 '12 at 14:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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