命令用作html但不用作DOM [英] Command works as html but not as DOM

查看:52
本文介绍了命令用作html但不用作DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这适用于IE 6:


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"

http://www.w3.org/TR/html4/strict.dtd">

< html>

< head>

< title> aiff< / title>

< meta http-equiv =" Content-Type"含量=" text / html的;字符集= ISO-8859-1" />

< script language =" JavaScript" type =" text / javascript">

//<![CDATA [

function playMedia(){

document.getElementById (objMedia)。播放();

}

//]]>

< / script>

< / head>


< body>

< object id =" objMedia"

style =" visibility:hidden;"

classid =" CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"


codebase =" ; http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"

type =" application / x-oleobject" >

< param name =" FileName" value =" media / aif_sample.aif">

< param name =" AutoStart" value =" false">

< / object>


< div onclick =" playMedia();"风格= QUOT;位置:绝对的;左:475px;

顶部:242px;宽度:89px;高度:25像素; background-color:#00FFFF;"> Play< / div>

< / body>

< / html>

当我点击音频播放的div时,以下基于DOM的

代码不会:

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"

" http://www.w3.org/TR/html4/strict.dtd">

< html> ;

< head>

< title> aiff< / title>

< script type =" text / javascript"> ;

//<![CDATA [

window.onload = function(){

var audObj = document.createElement("对象");


audObj.setAttribute(" id"," objMedia");

audObj.setAttribute(" classid"," ... [clipped] ...");

audObj.setAttribute(" codebase"," ... [clipped] ...");

audObj.setAttribute(" type"," application / x-oleobject");


var audParam = document.createElement(" param");

audParam.setAttribute(" name"," FileName");

audParam.setAttribute(" value", " media / aif_sample.aif");

audObj.appendChild(audParam);


audParam = document.createElement(" param");

audParam.setAttribute(" name"," AutoStart");

audParam.setAttribute(" value"," false");

audObj.appendChild(audParam);


document.body.appendChild(audObj);

}

function playMedia (med){

document.getElementById(" objMedia")。Play();

}

//]]>

< / script>

< / head>


< body>

< ; div onclick =" playMedia();"风格= QUOT;光标:指针;位置:绝对;

左:475px;顶:242px;宽度:89px;高度:25像素; background-color:

#00FFFF;"> Play< / div>

< / body>

< / html>

页面按我的预期显示。没有返回错误但

音频永远不会开始播放。在idobjMedia上发出警报

返回Object。


如果我编辑代码以反映MZ会识别的设置那么它

在MZ播放。


为什么IE拒绝启动音频?


Andrew Poulos

解决方案

Andrew Poulos写道:

虽然这适用于IE 6:

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"
" http://www.w3.org/TR/html4/strict.dtd">
< html> ;
< head>
< title> aiff< / title>
< meta http-equiv =" Content-Type"含量=" text / html的;字符集= ISO-8859-1" />
< script language =" JavaScript" type =" text / javascript">
//<![CDATA [
function playMedia(){
document.getElementById(" objMedia")。Play();
}
//]]>
< / script>
< / head>

< body>
< object id =" objMedia"
style =" visibility:hidden;"
classid =" CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"

codebase =" http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"

type =" application / x- oleobject">
< param name =" FileName" value =" media / aif_sample.aif">
< param name =" AutoStart" value =" false">
< / object>

< div onclick =" playMedia();"风格= QUOT;位置:绝对的;左:475px;
顶部:242px;宽度:89px;高度:25像素; background-color:#00FFFF;"> Play< / div>
< / body>
< / html>




[限定]


除此之外,如果我使用innerHTML那么它也工作:

< script type =" text / javascript" ;>

//<![CDATA [

window.onload = function(){

var str ="< object id =''objMedia''" ;;

str + =" style =''visibility:hidden;''" ;;

str + =" classid =''... [clipped] ...''" ;;

str + =" codebase =''... [clipped] ...''" ;;

str + =" type =''application / x-oleobject''>" ;;

str + ="< param name =''FileName' 'value =''media / aif_sample.aif''>" ;;

str + ="< param name =''AutoStart''value =''false''>" ;;

str + ="< / object>" ;;


//我首先创建了一个空div在html中id为''med''

document.getElementById(" med")。innerHTML = str;


function playMedia(){

document.getElementById(" objMedia")。Play();

}

}

//] ]>

< / script>

为什么IE技术在IE中失败?


Andrew Poulos


2004年12月21日星期二16:42:56 +1100,Andrew Poulos< ap ***** @ hotmail.com>

写道:


[snip]

< script type =" text / javascript">
//<! [CDATA [


标记的部分在HTML中没有任何价值,因为用户代理不会将其解析为

SGML,因此更改< / in a字符串文字到< \ /仍然是必要的。你

可以在XHTML中使用它,但除非你以HTML格式提供页面

,否则不要使用评论。

但是,应避免使用脚本隐藏。只需将脚本放在

外部文件中。


[snip]

为什么IE技术在IE中失败? / blockquote>


可能是因为你正在使用setAttribute [2]。除非您编写脚本

XHTML文档,否则请使用DOM HTML模块

公开的快捷方式属性。


Mike

[1]在这种情况下,为什么heck还没有使用HTML?服务

XHTML作为HTML是浪费精力。

[2]无论如何,微软的setAttribute实现都被打破了。

界面完全不同,要设置类属性,

必须传递''className''作为属性名称。使用快捷方式

属性设置class属性时,只需要
。有趣的是,微软仍然认为他们正在追随W3C DOM。


-

Michael Winter

替换.invalid与.uk通过电子邮件回复。


Michael Winter写道:

2004年12月21日星期二16:42:56 +1100,Andrew Poulos < ap ***** @ hotmail.com>
写道:

[snip]

< script type =" text / javascript">
//<![CDATA [

标记的部分在HTML中没有任何价值,因为用户代理不会将其解析为SGML,所以将字符串文字中的< /更改为< \ /仍然是必要的。
您可以在XHTML中使用它但不要使用注释,除非您以HTML格式提供页面[ 1]。




这是我感到困惑的地方。我见过<! - 和 - >用过但有人

表示自Netscape 2以来没有必要这么做。而且当我看到代码样本时,我看到//<![CDATA [使用。

但是,应避免使用脚本隐藏。只需将脚本放在
外部文件中即可。


我一旦脚本工作就会把它移到外部文件中。

[snip]

为什么IE技术在IE中失败?
可能是因为你正在使用setAttribute [2]。除非您正在编写XHTML文档脚本,否则请使用DOM HTML模块公开的快捷方式属性。

Mike

[1]其中这个,为什么heck还没有使用HTML呢?服务
XHTML作为HTML是浪费精力。




我以为我将doctype设置为HTML 4 Strict ???

[2]无论如何,微软的setAttribute实现都被打破了。
界面完全不同,要设置类属性,您必须将''className''作为属性名称传递。在使用快捷方式
属性设置class属性时,这应该只是必要的。有趣的是,微软仍然试图暗示他们正在关注W3C DOM。




感谢您的建议,但我我不清楚你的意思是什么?快捷方式

属性是DOM HTML模块公开的。我知道的唯一捷径

是CSS。


Andrew Poulos


While this works on IE 6:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>aiff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" type="text/javascript">
//<![CDATA[
function playMedia() {
document.getElementById("objMedia").Play();
}
//]]>
</script>
</head>

<body>
<object id="objMedia"
style="visibility:hidden;"
classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"

codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"
type="application/x-oleobject">
<param name="FileName" value="media/aif_sample.aif">
<param name="AutoStart" value="false">
</object>

<div onclick="playMedia();" style="position:absolute; left:475px;
top:242px; width:89px; height:25px; background-color: #00FFFF;">Play</div>
</body>
</html>
that is when I click the div the audio plays, the following DOM-based
code doesn''t:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>aiff</title>
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
var audObj = document.createElement("object");

audObj.setAttribute("id", "objMedia");
audObj.setAttribute("classid"," ...[clipped]... ");
audObj.setAttribute("codebase"," ...[clipped]... " );
audObj.setAttribute("type","application/x-oleobject");

var audParam = document.createElement("param");
audParam.setAttribute("name","FileName");
audParam.setAttribute("value","media/aif_sample.aif");
audObj.appendChild(audParam);

audParam = document.createElement("param");
audParam.setAttribute("name","AutoStart");
audParam.setAttribute("value","false");
audObj.appendChild(audParam);

document.body.appendChild(audObj);
}
function playMedia(med) {
document.getElementById("objMedia").Play();
}
//]]>
</script>
</head>

<body>
<div onclick="playMedia();" style="cursor:pointer; position:absolute;
left:475px; top:242px; width:89px; height:25px; background-color:
#00FFFF;">Play</div>
</body>
</html>
The page appears as I expect it would. There are no errors returned but
the audio never starts playing. Doing an alert on the id "objMedia"
returns Object.

If I edit the code to reflect settings that MZ would recognise then it
plays in MZ.

Why does IE refuse to start the audio?

Andrew Poulos

解决方案

Andrew Poulos wrote:

While this works on IE 6:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>aiff</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" type="text/javascript">
//<![CDATA[
function playMedia() {
document.getElementById("objMedia").Play();
}
//]]>
</script>
</head>

<body>
<object id="objMedia"
style="visibility:hidden;"
classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"

codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"

type="application/x-oleobject">
<param name="FileName" value="media/aif_sample.aif">
<param name="AutoStart" value="false">
</object>

<div onclick="playMedia();" style="position:absolute; left:475px;
top:242px; width:89px; height:25px; background-color: #00FFFF;">Play</div>
</body>
</html>



[clipped]

Further to this, if I use innerHTML then it also ''works'':
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
var str = "<object id=''objMedia'' ";
str += "style=''visibility:hidden;'' ";
str += "classid=''...[clipped]...'' ";
str += "codebase=''...[clipped]...'' ";
str += "type=''application/x-oleobject''>";
str += "<param name=''FileName'' value=''media/aif_sample.aif''>";
str += "<param name=''AutoStart'' value=''false''>";
str += "</object>";

// I first created an empty div in the html with id ''med''
document.getElementById("med").innerHTML = str;

function playMedia() {
document.getElementById("objMedia").Play();
}
}
//]]>
</script>
Why is the DOM technique failing in IE?

Andrew Poulos


On Tue, 21 Dec 2004 16:42:56 +1100, Andrew Poulos <ap*****@hotmail.com>
wrote:

[snip]

<script type="text/javascript">
//<![CDATA[
Marked sections are of no value in HTML as user agents don''t parse it as
SGML, so changing </ in a string literal to <\/ is still necessary. You
can use it in XHTML but don''t use comments unless you''re serving the page
as HTML[1].

However, script hiding should be avoided. Just put the script in an
external file.

[snip]
Why is the DOM technique failing in IE?



Possibly because you''re using setAttribute[2]. Unless you''re scripting
XHTML documents, use the shortcut properties which the DOM HTML module
exposes.

Mike
[1] In which case, why the heck aren''t using HTML anyway? Serving
XHTML as HTML is a waste of effort.
[2] Microsoft''s implementation of setAttribute is broken anyway. The
interface is completely different and to set the class attribute,
you must pass ''className'' as the attribute name. That should only
be necessary when setting the class attribute using the shortcut
property. It''s interesting to note though that Microsoft still
try to imply that they''re following the W3C DOM.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


Michael Winter wrote:

On Tue, 21 Dec 2004 16:42:56 +1100, Andrew Poulos <ap*****@hotmail.com>
wrote:

[snip]

<script type="text/javascript">
//<![CDATA[

Marked sections are of no value in HTML as user agents don''t parse it
as SGML, so changing </ in a string literal to <\/ is still necessary.
You can use it in XHTML but don''t use comments unless you''re serving
the page as HTML[1].



This is where I get confused. I''ve seen <!-- and --> used but someone
said that this hasn''t been necessary since Netscape 2. And often when I
see code samples posted I see //<![CDATA[ used.
However, script hiding should be avoided. Just put the script in an
external file.
As soon as I get the script working I''ll move it into an external file.
[snip]

Why is the DOM technique failing in IE?
Possibly because you''re using setAttribute[2]. Unless you''re scripting
XHTML documents, use the shortcut properties which the DOM HTML module
exposes.

Mike
[1] In which case, why the heck aren''t using HTML anyway? Serving
XHTML as HTML is a waste of effort.



I thought I''d set the doctype as HTML 4 Strict???
[2] Microsoft''s implementation of setAttribute is broken anyway. The
interface is completely different and to set the class attribute,
you must pass ''className'' as the attribute name. That should only
be necessary when setting the class attribute using the shortcut
property. It''s interesting to note though that Microsoft still
try to imply that they''re following the W3C DOM.



Thanks for the advice but I''m unclear as to what you mean by "shortcut
properties which the DOM HTML module exposes". The only shortcuts I know
of are in CSS.

Andrew Poulos


这篇关于命令用作html但不用作DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆