开发者

Export/Retrieve unclickle links of images via javascript?

I use this to retrieve clickable links in a webpage:

javascript:(function(){as=document.getElementsByTagNa开发者_StackOverflow社区me(%22a%22);str=%22<ul>%22;for(i=0;i<as%20.length;i++){str+=%22<br><a%20href=%22+as[i].href+%22>%22+as[i].href+%22</a>\n%22}str+=%22</as></ul>%22;with(window.open()){document.write(str);document.close();}})()

But how do i retrieve unclickable image links in a web page? i don't have any knowledge in javascript :D


If you are not using any js frameworks like jQuery/ExtJS etc, then you resort to this solutin:

<input type="button" value="Calculate" onclick="checkImages()"/>
    <a href="http://google.com">Google</a>
    <a href="http://google.com"><img src="1" /> sss</a>
    <a href="http://google.com"><span><img src="2" /> sss</span></a>
    <img src="3" />
    <img src="4" />
    <div id="outputDiv">
    </div>
    <script type="text/javascript"> 
        function checkImages()
        {
                var str="<ul>";
                var imgs = document.getElementsByTagName("IMG");
                var len = imgs.length;
                for(var i=0; i<len; i++)
                {
                    var img = imgs[i];
                    //console.log("Checking" + img);
                    if(!hasParentAnchor(img))
                    {
                        str+="<li><img src="+img.src+"/></li>";
                    }
                }
                document.getElementById("outputDiv").innerHTML = str;
        }

        function hasParentAnchor(el)
        {
            if(!el.parentNode || !el.parentNode.tagName) return false;
            else if(el.parentNode.tagName.toUpperCase() == "A") return true;
            else return hasParentAnchor(el.parentNode);
        }
    </script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜