求助
下面是一个网文提取软件中的一个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 = /(<)/gi;
var rv = str.replace(re,"<");
re = /(>)/gi;
rv = rv.replace(re,">");
//re = /( )/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>