0

I currently have a list of links to external web sites on a homepage in a summary web part view. These links include Google, the company's website, newspaper sites etc. Instead of the bullet point (square.gif) that Sharepoint uses, I want an actual logo of the website that it links to.

I have tried adding columns like 'type' but it just displays an image saying it links to another webpage, which I don't want.

I came across this thread: The very last answer looks like something I could use:

    <script language="javascript" type="text/javascript">
    var arrElements = document.getElementsByTagName("img");
    for (var i=0; i<arrElements.length; i++) {
            //get pointer each image element:
            var element=arrElements[i];
            //check for a source with /images/square.gif from this site:
            if (element.getAttribute('src') == 
                      "http://www.MY-SITE-NAME.com/_layouts/images/square.gif") {
                //found... change it's src to our new image:
                element.setAttribute('src', 'http://www.MY-SITE-NAME.com/MY-LOCATION/MY-CUSTOM-BULLET.gif');
            }
        }
</script>

I need to change where it sets each point to the same picture, to javascript looking at each website and retrieving the logo thumbnail (something like the little picture in the tab at the top of the browsers).

4

1 回答 1

0

我相信你需要 jQuery 的力量。这应该会让你更进一步:

<html>
 <head>
  <title> New Document </title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
 </head>

 <body>
<ul id="myList">
    <li><a href="http://www.google.gr">google</a></li>  
    <li><a href="http://news.in.gr">in news</a></li>    
    <li><a href="http://www.star.gr">star</a></li>  
</ul>
<script type="text/javascript">
$('#myList li').each(function() {
    var href = $(this).children("a").prop("href");
    var discImage = "url('" + href + "favicon.ico')";
    // alert(discImage );
    $(this).css("list-style-image", discImage);
});
</script>
</body>
</html>

favicon 是(可能)唯一在所有站点中具有相同名称的图像,但并不总是相同的大小(例如检查谷歌)。

现场演示在这里--> http://jsfiddle.net/Mt7XA/享受!

于 2012-12-20T22:34:40.500 回答