`
lzj0470
  • 浏览: 1263611 次
  • 性别: 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>
分享到:
评论

相关推荐

    document.execCommand()的用法

    19. **CreateBookmark**: 创建书签。 20. **FormatBlock**: 设置块级元素格式。 21. **FontName**: 设置字体名称。 22. **FontSize**: 设置字体大小。 23. **ForeColor**: 设置前景色(文本颜色)。 24. **BackColor...

    document.execCommand()解析

    6. `createlink`:创建链接。 7. `unlink`:移除链接。 8. `indent`:增加缩进。 9. `outdent`:减少缩进。 10. `copy`:复制选定内容。 11. `cut`:剪切选定内容。 12. `paste`:粘贴内容。 三、使用示例 下面是一...

    execCommand指令集详解

    execCommand指令集详解,javascript进阶是常用的参考资料

    javascript 的execCommand和操作剪贴板

    javascript 的execCommand和操作剪贴板的收集

    html中的内容直接下载到excel中,替换 document.execCommand(‘saveAs’)方法

    传统的做法是使用`document.execCommand('saveAs')`方法,但这个方法在某些现代浏览器中已被废弃,因此需要寻找替代方案。本篇文章将详细探讨如何在不依赖`execCommand('saveAs')`的情况下,实现HTML内容直接下载到...

    Js之execCommand解析.pdf

    6. `"CreateLink"`:在选定内容上插入超链接,或弹出对话框让用户输入链接地址。 7. `"Cut"`:复制选定内容到剪贴板并从文档中删除。 8. `"Delete"`:删除选定内容。 9. `"FontName"`:设置或获取选定文本的字体。 ...

    document.execCommand()的用法小结

    12. **CreateLink**: 插入超链接,用户可以选择输入链接地址或者直接插入预设的链接。 13. **Unlink**: 移除选中链接。 14. **Cut / Copy / Paste**: 剪切、复制和粘贴当前选中内容。 15. **Undo / Redo**: 取消和...

    类似qq空间中的留言编辑器

    case 7: E.document.execCommand('CreateLink',true,'true') break; case 8: if(_Text!='') { var _CText=RemoveHTML(_Text); Ebody.innerHTML=Ebody.innerHTML.replace(_Text,_CText); }else{ if...

    javascript document.execCommand() 常用解析

    2D-Position 允许通过拖曳移动绝对定位的对象。 AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。... CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区插入的超级

    document对象execCommand的command参数介绍

    2D-Position 允许通过拖曳移动绝对定位的对象。 AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。... CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当

    HTML网页跳转微信添加好友/点击自动复制微信号一键跳转到微信

    为了实现自动复制微信号,JavaScript可以利用浏览器提供的Web API,如`document.execCommand('copy')`,来复制文本到剪贴板。在用户点击按钮后,JavaScript会获取预先设定的微信号,并调用这个API,使得用户无需手动...

    用javascript做的文本编辑器

    document.execCommand('CreateLink', true, 'true'); // 创建链接 // document.execCommand('CreateLink', false, 'http://www.51js.com'); // 创建指向特定URL的链接 } ``` #### 4. 设置字体颜色 ```javascript ...

    在JavaScript中如何解决用execCommand(

    在Web开发中,经常需要实现将页面中的内容保存到用户的本地设备上的功能,这通常可以通过JavaScript中的execCommand命令实现,特别是使用"SaveAs"命令。然而,由于浏览器的兼容性问题,这种方法并不总是有效的。在IE...

    另存為按鈕.html

    - **创建链接**:使用 `document.execCommand("CreateLink")` 来将选中的文本转换为链接。这实际上是调用了浏览器的内置命令来创建链接。 - **替换文本为URL**:检查是否已成功创建链接,并将链接文本替换为其URL...

    自制富文本编辑框

    document.execCommand('createLink', false, url); } }); ``` 在描述中提到的“图片上传”功能,通常需要额外的后端支持。可以添加一个“上传图片”按钮,当用户选择图片后,通过Ajax发送文件到服务器,服务器...

    execcommand:一个非常简单的包装器,用于在 NodeJS 中同步执行系统命令!

    执行命令 一个非常简单的包装器,用于在 NodeJS ... var execCommand = require ( "execCommand.js" ) ; var command = execCommand ( "cat /sys/class/thermal/thermal_zone0/temp" ) ; console . log ( command ) ;

    excCommand命令

    - **示例**: `document.execCommand("CreateLink", "false", "http://example.com")` - **支持版本**: 当前支持 - **备注**: 在选中的文本上创建一个超链接,并指向指定的 URL 地址。 ##### 11. Cut - **命令**: `...

    cument.execCommand()用法深入理解

    代码如下: D-Position 允许通过拖曳移动绝对定位的对象。 AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。... CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区

Global site tag (gtag.js) - Google Analytics