| | |
document.getElementById not working in IE. Why?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 8
Reputation:
Solved Threads: 0
First a little background. I have a client (in-house) who insists that our training pages (launched from within iframes on a parent page) be able to load .wmv files with variables for the width and height parameters so we don't have to recode when videos are switched. Flash videos are not an option.
I've searched the net and have received several suggestions and even code snippets from several sources but the only one that comes close to working is this one:
I say close because it works just fine in Firefox (go figure) but doesn't appear to be working correctly in IE. IE just will not load the video using the "objectSrc" id. If I move the source video from the javascript into the actual object, then it loads and plays the video (it still doesn't resize the window correctly).
I've been in several forums and have poured over the code with several people and we just can't figure out why this code doesn't work correctly.
Can anyone here help?
Thanks,
M.
I've searched the net and have received several suggestions and even code snippets from several sources but the only one that comes close to working is this one:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <style type="text/css"> <!-- .fontStyle { font-family: Verdana, Geneva, sans-serif; font-size: small; font-weight: bold; color: #67A2DC; } --> </style> <script type="text/javascript"> window.onload=function(){ loadVideo(); } function loadVideo() { if (parseInt(navigator.appVersion)>3) { if (navigator.appName == "Netscape") { winW = window.innerWidth; winH = window.innerHeight; } if (navigator.appName.indexOf("Microsoft") != -1) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } } var dimW = winW-50; var dimH = winH-20; var w1 = dimW.toString(); var h1 = dimH.toString(); if(document.getElementById("vidEmbed") != null) { document.getElementById("vidEmbed").src = "Welcome_1.wmv"; document.getElementById("vidEmbed").style.width = w1; document.getElementById("vidEmbed").style.height = h1; } else if(document.getElementById("Player") != null) { document.getElementById("Player").style.width = w1; document.getElementById("Player").style.height = h1; document.getElementById("objectSrc").value = "Welcome_1.wmv"; } } </script> </head> <body><div> <p><span class="fontStyle">Introduction<br> </span> <object id="Player" width="100%" height="100%" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="border:0px;"> <param name="autoStart" value="True"> <param name="uiMode" value="full"> <param name="volume" value="50"> <param name="mute" value="false"> <param name="URL" id="objectSrc" value=""> <embed src="" id="vidEmbed" width="100%" height="100%" autostart="true" uimode="full" volume="50" mute="false"> </embed> </object> </p> </div> </body> </html>
I say close because it works just fine in Firefox (go figure) but doesn't appear to be working correctly in IE. IE just will not load the video using the "objectSrc" id. If I move the source video from the javascript into the actual object, then it loads and plays the video (it still doesn't resize the window correctly).
I've been in several forums and have poured over the code with several people and we just can't figure out why this code doesn't work correctly.
Can anyone here help?
Thanks,
M.
You could try an
First rewrite the HTML as follows:
Then in javascript,
(Not tested)
Then use global regular expression
Agreed, it shouldn't be necessary but it might just work.
You can do this within a
Airshow
innerHTML approach rather than trying to reuse the object/embed with DHTML.First rewrite the HTML as follows:
HTML Syntax (Toggle Plain Text)
<body> <p><span class="fontStyle">Introduction</span></p> <div id="video"> <object id="Player" width="100%" height="100%" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="border:0px;"> <param name="autoStart" value="True"> <param name="uiMode" value="full"> <param name="volume" value="50"> <param name="mute" value="false"> <param name="URL" id="objectSrc" value=""> <embed src="" id="vidEmbed" width="100%" height="100%" autostart="true" uimode="full" volume="50" mute="false"> </embed> </object> </div> </body>
javascript Syntax (Toggle Plain Text)
var videoString = "<object id=\"Player\" width=\"%sW\" height=\"%sH\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" style=\"border:0px;\">" + "<param name=\"autoStart\" value=\"True\">" + "<param name=\"uiMode\" value=\"full\">" + "<param name=\"volume\" value=\"50\">" + "<param name=\"mute\" value=\"false\">" + "<param name=\"URL\" value=\"%sURL\">" + "<embed src=\"%sURL\" width=\"%sW\" height=\"%sH\" autostart=\"true\" uimode=\"full\" volume=\"50\" mute=\"false\"></embed>" + "</object>";
Then use global regular expression
videoString.replace(.....) to replace %sW, %sH, %sURL with appropriate values and document.getElementById("video").innerHTML = .... to poke this HTML into the DOM.Agreed, it shouldn't be necessary but it might just work.
You can do this within a
if(){} condition such that it only applies to IE thus leaving your good FF etc. code intact, and also allowing videoString to be simplified (no need for "<embed ....>").Airshow
Last edited by Airshow; Sep 30th, 2009 at 5:38 pm.
50% of the solution lies in accurately describing the problem!
html Syntax (Toggle Plain Text)
<script type="text/javascript"> <!--// function setplay(thisfile,ww,hh) { document.getElementById("MediaPlayer1").src=thisfile; document.getElementById("MediaPlayer1").style.width=ww; document.getElementById("MediaPlayer1").style.height=hh; } //--> </script> <p><a href="http://www.microsoft.com/windows/windowsmedia/player/download/"><img alt="Get Windows Media Player" src="http://www.microsoft.com/windows/windowsmedia/images/logos/getwm/mp11_88x31_static.gif"width="88" height="31" border="0"></A><br> <object id="MediaPlayer1" width=384 height=300 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject"> <param name="fileName" value=""> <param name="showControls" value="true"> <param name="PlayCount" value="0"> <param name="animationatStart" value="true"> <param name="transparentatStart" value="true"> <param name="autoStart" value="true"> <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="" name="MediaPlayer1" width=360 height=260 AutoStart=true></embed></object></p> <a onclick='setfile("thisfile.wmv","480","300");' > Play thisfile </a><br> <a onclick='setfile("thatfile.wmv","400","320");' > Play thatfile </a>
Last edited by almostbob; Sep 30th, 2009 at 9:07 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
From his photo, I think that Bob is big enough to look after himself, but since I am around and Bob isn't, I hope he will forgive me for answering on his behalf.
Bob's script is written as a function,
I think you will find that IE will play ball with it as posted, but Moz browsers need 'px' to be specified explicitly.
Alternatively, leave Bob's code as is giving you the freedom to call with
or
as required.
If width and height need calculating, then
Airshow
Bob's script is written as a function,
setplay , such that thisfile , ww and hh are specified when it is called, eg. setplay('myvid1.wmv', '320', '240'); .I think you will find that IE will play ball with it as posted, but Moz browsers need 'px' to be specified explicitly.
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!--// function setplay(thisfile,ww,hh) { document.getElementById("MediaPlayer1").src=thisfile; document.getElementById("MediaPlayer1").style.width=ww+'px'; document.getElementById("MediaPlayer1").style.height=hh+'px'; } //--> </script>
setplay('myvid1.wmv', '320px', '240px'); ,or
setplay('myvid1.wmv', '100%', '100%'); ,as required.
If width and height need calculating, then
javascript Syntax (Toggle Plain Text)
var width = expression; var height = expression; setplay('myvid1.wmv', width+'px', height+'px');
Airshow
Last edited by Airshow; Oct 1st, 2009 at 1:22 pm.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Sep 2009
Posts: 8
Reputation:
Solved Threads: 0
Ok, I'm obviously missing something because for the life of me I can't get this work. First, what is setfile? Do you mean setplay? . Second, even though you've got the <a...> tags there, I am not seeing a hyperlink.
Third, where do I call the setplay function? In the <body>?
I've tried in the body and as window.onload=function(){setplay(somefile.wmv, 480, 300);} but still don't see anything playing.
So obviously, I'm not seeing something...
Thanks,
M.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<a onclick='setplay("oracleWelcome_1.wmv","480","300");' > Play thisfile </a><br> <a onclick='setfile("thatfile.wmv","400","320");' > Play thatfile </a>
Third, where do I call the setplay function? In the <body>?
I've tried in the body and as window.onload=function(){setplay(somefile.wmv, 480, 300);} but still don't see anything playing.
So obviously, I'm not seeing something...
Thanks,
M.
<html>
<head>
<style type="text/css">
<!--
.fontStyle {
font-family: Verdana, Geneva, sans-serif;
font-size: small;
font-weight: bold;
color: #67A2DC;
}
-->
</style>
<script type="text/javascript">
window.onload=function(){
loadVideo();
}
function loadVideo()
{
if (parseInt(navigator.appVersion)>3)
{
if (navigator.appName == "Netscape")
{
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft") != -1)
{
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
}
var dimW = winW-50;
var dimH = winH-20;
var w1 = dimW.toString();
var h1 = dimH.toString();
if(document.getElementById("vidEmbed") != null)
{
document.getElementById("vidEmbed").src = "Welcome_1.wmv";
document.getElementById("vidEmbed").style.width = w1;
document.getElementById("vidEmbed").style.height = h1;
}
else if(document.getElementById("Player") != null)
{
document.getElementById("Player").style.width = w1;
document.getElementById("Player").style.height = h1;
//document.getElementById("objectSrc").value = "Welcome_1.wmv";
document.getElementById("Player").url = "Welcome_1.wmv";}
}
</script>
</head>
<body><div>
<p><span class="fontStyle">Introduction<br>
</span>
<object id="Player" width="100%" height="100%" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="border:0px;">
<param name="autoStart" value="True">
<param name="uiMode" value="full">
<param name="volume" value="50">
<param name="mute" value="false">
<param name="URL" id="objectSrc" value="">
<embed src="" id="vidEmbed" width="100%" height="100%" autostart="true" uimode="full" volume="50" mute="false"> </embed>
</object>
</p>
</div>
</body>
</html>Set the
<param name="uiMode" value="none"> If you don't want player controls to appear on your media. Last edited by Troy III; Oct 2nd, 2009 at 1:07 pm.
safari is apple,
if a mac does the mac have windows media installed
from the "get windows media player" link included in the original script, that part of it works anyway
if a mac does the mac have windows media installed
from the "get windows media player" link included in the original script, that part of it works anyway
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
![]() |
Similar Threads
- document.getElementById...problem (JavaScript / DHTML / AJAX)
- document.getElementById problem (JavaScript / DHTML / AJAX)
- IE7 document.getElementById problem (JavaScript / DHTML / AJAX)
- need help to get document.getElementById to work (JavaScript / DHTML / AJAX)
- how do i get this to work document.getElementById (Java)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Safari Browser Doesn't Play This Video: Why Not?
- Next Thread: Photo Gallery Caption Won't Change
Views: 1051 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets api blackjack browser bug captchaformproblem checkbox child class close cookies createrange() cursor date debugger dependent developer disablefirebug dom dropdown editor element embed engine events explorer ext file flash form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl maps margin math matrixcaptcha media mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming progressbar rated runtime safari scriptlets scroll search security session shopping size software solutions star stars stretch synchronous tweet unicode web webkit webservice window wysiwyg \n






