0

This jQuery should give me thumbnail view of the icjpg.gif but it does not give the actual image that are in the document library. Any idea what I am doing wrong? It just gives me the sharepoint icjpg.gif in bigger size. It's supposed to be working. http://sharepointblog.kellerschroeder.com/2009/05/using-jquery-to-display-image.html enter image description here

<SCRIPT defer type=text/javascript> 
$(document).ready(function(){ 
$("img[src$='icjpg.gif']").each(SetImage); 

}); 
function SetImage() 
{ 

$(this).attr('height','100'); 
$(this).attr('src',$(this).parent().attr('href')); 

} 
</SCRIPT>
2

There seems to be a problem locating the parent href attribute. I did notice that the object itself has a title attribute. So here is a workaround:

<SCRIPT defer type=text/javascript>
$(document).ready(function(){
$("img[src$='icjpg.gif']").each(SetImage);

});
function SetImage()
{
    $(this).attr('height','100');
    $(this).attr('src','/<<your document library name>>/'+$(this).attr('title'));
    // try this code
    //$(this).attr('src','/managedpath/sitename/library/'+$(this).attr('title')); 
}
</SCRIPT>

Also just wondering why you could not just use a picture library and get all the preview options inbuilt?

  • I can't use picture library as this library is the place for all types of documents. I created a view for pictures only. The code you provided does the same thing with my originally posted code. Any other ideas? – Morgan Feb 19 '15 at 17:43
  • Are you sure? The code I posted above I have tested on my site. Can you post the setImage() function code as you have modified it for your library? This is how it looks for me: $(this).attr('src','/test/'+$(this).attr('title')); Here test is the name of my document library – Ransher Singh Feb 19 '15 at 17:46
  • I have posted the picture with my original post on how it looks like. Here is my non working code $(this).attr('src','/InfrastructureDocuments/'+$(this).attr('title')); – Morgan Feb 19 '15 at 17:55
  • $(this).attr('src','/managedpath/sitename/library/'+$(this).attr('title')); this worked. Thanks Ransher for your valuable support. I truly appreciate it. Thanks Eric for pitching in and help us out. – Morgan Feb 19 '15 at 17:57
2

Ah, it is working, but the URL to the picture is malformed, hence the x images. This is what worked for me:

<script type="text/javascript">
$(document).ready(function(){
$("img[src$='icjpg.gif']").each(SetImage);

});
function SetImage()
{
    $(this).attr('height','100');
    $(this).attr('src','/managedpath/sitename/library/'+$(this).attr('title'));
}
</script>

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.