| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 836 人关注过本帖
标题:求助
只看楼主 加入收藏
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
结帖率:100%
收藏
 问题点数:0 回复次数:1 
求助
下面是一个网文提取软件中的一个HTML, 它是通过在IE选择文字,然后通过IE菜单,打开此HTML, 然后得到文字以及链接, 然后调用一个自写的Open7Txt.dll,实现将内容发送到它的程序中.. 我对javascript太弱了..

谁能帮我改改,需要实现的功能: 将选择的文字,以及里面包含的链接, 放至到变量xxxstr中就行..
<script language="javascript">
                var userURL=external.menuArguments.location.href;
                var docbody=external.menuArguments.document;
                var linksbody;
                linksbody=docbody.selection.createRange().htmlText;
                if(linksbody=='')
                        linksbody=getlinkbody();
                //alert(linksbody);
                var _7txtObj = new ActiveXObject("Open7Txt.Tool");
                if(!docbody.getElementById('_7Txt'))
                {
                        var __7TxtDiv=docbody.createElement("div");
                        __7TxtDiv.setAttribute("id","_7Txt");
                        __7TxtDiv.style.display="none";
                        docbody.body.appendChild(__7TxtDiv);
                }else{
                        __7TxtDiv=docbody.getElementById('_7Txt');
                }
                __7TxtDiv.innerHTML=linksbody;//为了使链接转换为URL,只好这样了....
                var winname = window.open('', '_blank', 'top=10000');
                winname.document.open('text', '');
                winname.document.writeln(__7TxtDiv.innerHTML);
               
                linksbody='';
                _7txtObj.openSoft();//打开软件
                //_7txtObj.chkStatus(1);
                //var SelectLink = b.links[i].href;
                _7txtObj.AddData('start',userURL);
                for (var i=0; i<winname.document.links.length; i++) {
                   var oneLink = winname.document.links[i];
                   var mystr   = oneLink.href+'$$$$$'+htmldecode(oneLink.innerText);
                   //linksbody+='<a href="'+oneLink.href+'">'+
                                        //oneLink.innerHTML+'</a>';
                        _7txtObj.AddData(mystr,userURL);
                        //执行添加文章
                }
                winname.close();
                _7txtObj.AddData('over',userURL);
                //_7txtObj.chkStatus(2);这两个参数留着以后用
                function htmldecode(str)
                {
                        var re = /(&lt;)/gi;
                        var rv = str.replace(re,"<");
                        re = /(&gt;)/gi;
                        rv = rv.replace(re,">");
                        //re = /(&nbsp;)/gi;
                        //rv = rv.replace(re," ");
                        return(rv);
                }


function getlinkbody()
{

        var srcEvent = external.menuArguments.event;
        var EventElement;
        
        if(typeof(srcEvent.clientX) == "undefined")
        {
                EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.pointerX, srcEvent.pointerY );
        }
        else
        {
                EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY );
        }
        
        if (srcEvent.type == "MenuExtAnchor"){
                srcAnchor = EventElement;
                do
                {
                        srcAnchor=srcAnchor.parentElement;
                }while(typeof(srcAnchor)=="HTMLAnchorElement");
                return "<a href=\""+srcAnchor.href+"\">"+srcAnchor.innerText+"</a>";
        }
        else if (srcEvent.type == "MenuExtImage")
        {
                if (typeof(EventElement) == "HTMLAreaElement")
                {
                        linksbody="<a href=\""+EventElement.href+"\">"+EventElement.Alt+"</a>";
                }
                else
                {
                        var srcImage = EventElement;
                        var srcAnchor = srcImage.parentElement;
                        do
                        {
                                srcAnchor=srcAnchor.parentElement;
                                if (typeof(srcAnchor) == "undefined")
                                {
                                        return "<a href=\""+srcImage.href+"\">"+srcImage.Alt+"</a>";
                                       
                                }
                        }while(typeof(srcAnchor) == "HTMLAnchorElement");
                        return "<a href=\""+srcAnchor.href+"\">"+srcImage.Alt+"</a>";
                }
        }        
        else if (srcEvent.type == "MenuExtUnknown")
        {
        srcAnchor = EventElement;
        if(srcAnchor != null && srcAnchor.tagName != null && srcAnchor.tagName.toLowerCase() == "a")
            {
               return "<a href=\""+srcAnchor.href+"\">"+srcAnchor.innerText+"</a>";
            }
            else
            {
                while(srcAnchor != null && srcAnchor.tagName != null && srcAnchor.tagName.toLowerCase() != "a")
                {
                    srcAnchor = srcAnchor.parentElement;
                    if(srcAnchor != null && srcAnchor.tagName != null && srcAnchor.tagName.toLowerCase() == "a")
                    {
                        return "<a href=\""+srcAnchor.href+"\">"+srcAnchor.innerText+"</a>";
                    }
                }
                        
                if(EventElement != null && EventElement.tagName != null)
                {
                    return "<a href=\""+EventElement.href+"\">"+EventElement.innerText+"</a>";
                }
                else
                {
                    alert("无法识别的超级链接信息");
                }
            }
        }
        else
        {
               
        }
}
</script>
搜索更多相关主题的帖子: javascript 软件 
2008-01-09 03:33
渚薰
Rank: 6Rank: 6
等 级:贵宾
威 望:22
帖 子:1132
专家分:0
注 册:2006-8-6
收藏
得分:0 
源代码中,mystr 这个是得到链接,你用一个数组,分别push进去每个mystr就行了

个人ajax技术专题站: " target="_blank">http://www. 我不会闲你烦,只会闲你不够烦!
2008-01-09 08:37
快速回复:求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020173 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved