`
lzj0470
  • 浏览: 1246951 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

execCommand CreateLink 添加Target

    博客分类:
  • jsp
Web 
阅读更多
<HTML>
<BODY>
<H1 unselectable="on">Creating a Link and Retrieving the URL</H1>
<script>
function AddLink(){//Identify selected textvar 
	sText = document.selection.createRange();
	if (!sText==""){
		//Create link
		document.execCommand("CreateLink");
		var len = sText.parentElement().childNodes.length;
		for(var i=0;i<len;i++){
			if (sText.parentElement().childNodes[i].tagName == "A"){
				sText.parentElement().childNodes[i].target = "_blank"; 
			}
		}
	}else{
		alert("Please select some blue text!");
	}
}
</script>
<P unselectable="on">Select any portion of the following blue text, such as "My favorite Web site". Click the button to turn the selected text into a link. The text will be changed to the URL that you specify.</P>
<P style="color=#3366CC">My favorite Web site is worth clicking on. Don't forget to check out my favorite music group!</P>
<BUTTON onclick="AddLink()" unselectable="on">Click to add link</BUTTON>
</BODY>
</HTML>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics