如何测试特定于浏览器的方法,如document.selection.createRange [英] how to test for browser specific methods like document.selection.createRange
问题描述
这是在我使用它之前测试方法的正确方法吗?
createRange()我相信是一种IE唯一的方法。
function wrapSelectionInTag(选择,标记){
if(document.selection.createRange){
var range = document.selection.createRange();
if (range.parentElement()== element)range.text =''<''+ tag +
''>''+ range.text +''< \ /' '+ tag +''>'';
}
}
2004年11月20日13:06:32 -0800,劳伦斯< lk ****** @ geocities.com>写道:
这是在我使用之前测试方法的正确方法吗?
差不多。您还需要检查对象,选择。
if(document.selection&& document.selection.createRange){
var range = document.selection.createRange();
/ * ... * /
}
另外,
var sel;
if((sel = document.selection)&& sel.createRange){
var range = sel.createRange();
/ * ... * /
}
createRange()我认为是一种IE唯一的方法。
这是一种专有方法,但这并不一定意味着只有IE
支持它。不过,我不能说出其他人的名字。
[snip]
Mike
*请不要在Usenet上使用标签进行缩进。在发布之前将它们转换为空格
。
-
Michael Winter
替换 。无效"与.uk通过电子邮件回复。
Michael Winter写道:
[...]createRange(),我认为是IE唯一的方法。
这是一种专有方法,但这并不一定只意味着IE
支持它。但是,我不能说出任何其他人的名字。
似乎已经在DOM Level 2中采用了
< URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level2-DocumentRange-method-createRange>
我已经在Mozilla和Safari中测试了它(它的工作原理......)。
Rob。
On Sun,2004年11月21日21:16:16 +1000,RobG< rg *** @ iinet.net.auau>写道:
Michael Winter写道:
[snip]
< blockquote class =post_quotes> [createRange]是一种专有方法,但并不一定意味着只有IE支持它。但是,我不能说出任何其他人的名字。
似乎已经在DOM Level 2中采用了
[URL到DOM 2 Traveral和范围规格]
[snip]
据我所知,它们是两回事。
由Microsoft引入的document.selection.createRange方法,
反映了用户选择的文本。
文档由W3C引入的.createRange方法选择文档树的
部分,允许你将它作为一个块操作
(基本上)。
Mike
-
Michael Winter
替换.invalid与.uk通过电子邮件回复。
Is this the correct way to test for a method before I use it?
createRange() is, I believe, an IE only method.
function wrapSelectionInTag(selection, tag) {
if (document.selection.createRange) {
var range = document.selection.createRange();
if (range.parentElement() == element) range.text = ''<'' + tag +
''>'' + range.text + ''<\/'' + tag + ''>'';
}
}
On 20 Nov 2004 13:06:32 -0800, lawrence <lk******@geocities.com> wrote:
Is this the correct way to test for a method before I use it?
Nearly. You need to check for the object, selection, as well.
if(document.selection && document.selection.createRange) {
var range = document.selection.createRange();
/* ... */
}
Alternatively,
var sel;
if((sel = document.selection) && sel.createRange) {
var range = sel.createRange();
/* ... */
}
createRange() is, I believe, an IE only method.
It is a proprietary method, but that doesn''t necessarily mean only IE
supports it. I can''t name any others that do, though.
[snip]
Mike
*Please* don''t use tabs for indentation on Usenet. Convert them to spaces
before posting.
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Michael Winter wrote:
[...]createRange() is, I believe, an IE only method.
It is a proprietary method, but that doesn''t necessarily mean only IE
supports it. I can''t name any others that do, though.
Seems it''s been adopted in DOM Level 2
<URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level2-DocumentRange-method-createRange>
I''ve tested it in Mozilla and Safari (it works...).
Rob.
On Sun, 21 Nov 2004 21:16:16 +1000, RobG <rg***@iinet.net.auau> wrote:
Michael Winter wrote:
[snip]
[createRange] is a proprietary method, but that doesn''t necessarily
mean only IE supports it. I can''t name any others that do, though.
Seems it''s been adopted in DOM Level 2
[URL to DOM 2 Traveral and Range Specification]
[snip]
As I understand it, they are two different things.
The document.selection.createRange method, as introduced by Microsoft,
reflects text selected by the user.
The document.createRange method, as introduced by the W3C, selects a
portion of the document tree, allowing you to manipulate it as a block
(essentially).
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
这篇关于如何测试特定于浏览器的方法,如document.selection.createRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!