473,586 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another DOM question concerning IE & Opera createElement

63 New Member
Why am I having so much trouble with using DOM in IE & Opera to create, then remove an Object & Embedded element?

Here's the code that works in Firefox (Mac/Win/Linux) and Safari, but not on IE or Opera:

Expand|Select|Wrap|Line Numbers
  1.     var myfl_div = document.createElement('myfldiv');
  2.     myfl_div.setAttribute('style','position:absolute; left:100px; top:200px; width:960px; height: 560px; background-color: transparent;z-index: 5;');
  3.  
  4. function myFl_obj_emb()
  5. {
  6.  
  7.     var myBgDiv = document.getElementById('autismlogo');
  8.     myBgDiv.innerHTML = '';
  9.     myBgDiv.innerHTML = '<img src="images/bg5.jpg" usemap="#bg" border="0" alt="Autism the Musical">';
  10.  
  11.     var myAutismFlshObj = document.createElement('object');
  12.     myAutismFlshObj.setAttribute('classid','clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');
  13.     myAutismFlshObj.setAttribute('codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0');
  14.     myAutismFlshObj.setAttribute('width','960');
  15.     myAutismFlshObj.setAttribute('height','560');
  16.     myAutismFlshObj.setAttribute('id','autismIntro');
  17.  
  18.     var myAutismFlshObjParam1 = document.createElement('param');
  19.     myAutismFlshObjParam1.setAttribute('name','allowScriptAccess');
  20.     myAutismFlshObjParam1.setAttribute('value','sameDomain');
  21.  
  22.     var myAutismFlshObjParam2 = document.createElement('param');
  23.     myAutismFlshObjParam2.setAttribute('name','movie');
  24.     myAutismFlshObjParam2.setAttribute('value','autism_intro3.swf');
  25.  
  26.     var myAutismFlshObjParam3 = document.createElement('param');
  27.     myAutismFlshObjParam3.setAttribute('name','quality');
  28.     myAutismFlshObjParam3.setAttribute('value','high');
  29.  
  30.     var myAutismFlshObjParam4 = document.createElement('param');
  31.     myAutismFlshObjParam4.setAttribute('name','bgcolor');
  32.     myAutismFlshObjParam4.setAttribute('value','#000000');
  33.  
  34.     var myAutismFlshObjParam6 = document.createElement('param');
  35.     myAutismFlshObjParam6.setAttribute('name','id');
  36.     myAutismFlshObjParam6.setAttribute('value','autismIntro');
  37.  
  38.  
  39.     var myAutismFlshEmbed = document.createElement('embed');
  40.     myAutismFlshEmbed.setAttribute('src','autism_intro3.swf');
  41.     myAutismFlshEmbed.setAttribute('quality','high');
  42.     myAutismFlshEmbed.setAttribute('bgcolor','#000000');
  43.     myAutismFlshEmbed.setAttribute('width','960');
  44.     myAutismFlshEmbed.setAttribute('height','560');
  45.     myAutismFlshEmbed.setAttribute('name','autism_intro3');
  46.     myAutismFlshEmbed.setAttribute('id','autismIntro');
  47.     myAutismFlshEmbed.setAttribute('align','middle');
  48.     myAutismFlshEmbed.setAttribute('allowScriptAccess','sameDomain');
  49.     myAutismFlshEmbed.setAttribute('type','application/x-shockwave-flash');
  50.     myAutismFlshEmbed.setAttribute('pluginspage','http://www.macromedia.com/go/getflashplayer');
  51.  
  52.     document.body.appendChild(myfl_div);
  53.     myfl_div.appendChild(myAutismFlshObj);
  54.     myAutismFlshObj.appendChild(myAutismFlshObjParam1);
  55.     myAutismFlshObj.appendChild(myAutismFlshObjParam2);
  56.     myAutismFlshObj.appendChild(myAutismFlshObjParam3);
  57.     myAutismFlshObj.appendChild(myAutismFlshObjParam4);
  58.     myAutismFlshObj.appendChild(myAutismFlshObjParam6);
  59.     myAutismFlshObj.appendChild(myAutismFlshEmbed);
  60. }
  61.  
  62. function myfl_obj_emb_remove()
  63. {
  64.     document.body.removeChild(myfl_div);
  65. }
  66.  
Any help is always appreciated and thanks in advance
Sep 21 '07 #1
7 2516
acoder
16,027 Recognized Expert Moderator MVP
IE doesn't support creating object elements via the createElement method properly. In fact, input elements can't be created properly either. You have to use the whole HTML string. I'm not sure about Opera.

On your first line, you're creating an invalid element.
Sep 21 '07 #2
Tarik Monem
63 New Member
Thanks for the reply.

I thought that might be the case, but I was hoping that maybe there was a chance of a little different syntax for IE. What do you mean by "write it as one string?"

If I can not create an Element using the DOM, then how do I go about removing an embedded flash object from IE?

That was the whole point of using the DOM, was so that I could call removeChild()

Once more, any help is appreciated and thanks in advance.

You guys are the greatest :-)
Sep 21 '07 #3
Tarik Monem
63 New Member
OK, this is what I've tried to do, which gives me no errors and the DOM inspector for both Opera and IE show that the nodes are there.

So, what am I doing wrong?

Expand|Select|Wrap|Line Numbers
  1. function myFl_obj_emb_ms()
  2. {
  3.     var myBgDiv = document.getElementById('autismlogo');
  4.     myBgDiv.innerHTML = '';
  5.     myBgDiv.innerHTML = '<img src="images/bg5.jpg" usemap="#bg" border="0" alt="Autism the Musical">';
  6.  
  7.     var myAutismFlshObj = document.createElement('object');
  8.     myAutismFlshObj.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
  9.     myAutismFlshObj.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
  10.     myAutismFlshObj.width = '640';
  11.     myAutismFlshObj.height = '560';
  12.     myAutismFlshObj.id = 'autismIntro';
  13.     myAutismFlshObj.movie = 'autism_intro3.swf';
  14.  
  15.     var myAutismFlshObjParam1 = document.createElement('param');
  16.     myAutismFlshObjParam1.name = 'allowScriptAccess';
  17.     myAutismFlshObjParam1.value = 'sameDomain';
  18.  
  19.     var myAutismFlshObjParam2 = document.createElement('param');
  20.     myAutismFlshObjParam2.name = 'movie';
  21.     myAutismFlshObjParam2.value = 'autism_intro3.swf';
  22.  
  23.     var myAutismFlshObjParam3 = document.createElement('param');
  24.     myAutismFlshObjParam3.name = 'quality';
  25.     myAutismFlshObjParam3.value = 'high';
  26.  
  27.     var myAutismFlshObjParam4 = document.createElement('param');
  28.     myAutismFlshObjParam4.name = 'bgcolor';
  29.     myAutismFlshObjParam4.value = '#000000';
  30.  
  31.     var myAutismFlshObjParam5 = document.createElement('param');
  32.     myAutismFlshObjParam5.name = 'play';
  33.     myAutismFlshObjParam5.value = 'true';
  34.  
  35.     var myAutismFlshObjParam6 = document.createElement('param');
  36.     myAutismFlshObjParam6.name = 'id';
  37.     myAutismFlshObjParam6.value = 'autismIntro';
  38.  
  39.  
  40.     var myAutismFlshEmbed = document.createElement('embed');
  41.     myAutismFlshEmbed.src = 'autism_intro3.swf';
  42.     myAutismFlshEmbed.quality = 'high';
  43.     myAutismFlshEmbed.play = 'true';
  44.     myAutismFlshEmbed.bgcolor = '#000000';
  45.     myAutismFlshEmbed.width = '640';
  46.     myAutismFlshEmbed.height = '560';
  47.     myAutismFlshEmbed.name = 'autism_intro3';
  48.     myAutismFlshEmbed.id = 'autismIntro';
  49.     myAutismFlshEmbed.align = 'middle';
  50.     myAutismFlshEmbed.allowScriptAccess = 'sameDomain';
  51.     myAutismFlshEmbed.type = 'application/x-shockwave-flash';
  52.     /*myAutismFlshEmbed.pluginspage = 'http://www.macromedia.com/go/getflashplayer';*/
  53.  
  54.     document.body.appendChild(myfl_div);
  55.     document.body.appendChild(myAutismFlshObj);
  56.     document.body.appendChild(myAutismFlshObjParam1);
  57.     document.body.appendChild(myAutismFlshObjParam2);
  58.     document.body.appendChild(myAutismFlshObjParam3);
  59.     document.body.appendChild(myAutismFlshObjParam4);
  60.     document.body.appendChild(myAutismFlshObjParam5);
  61.     document.body.appendChild(myAutismFlshObjParam6);
  62.     document.body.appendChild(myAutismFlshEmbed);
  63. }
  64.  
  65. function myfl_obj_emb_remove()
  66. {
  67.     document.body.removeChild(myfl_div);
  68. }
  69.  
The remove function is called after the swf file has completed.

Once more, any help is appreciated and thanks in advance.
Sep 22 '07 #4
acoder
16,027 Recognized Expert Moderator MVP
I thought that might be the case, but I was hoping that maybe there was a chance of a little different syntax for IE. What do you mean by "write it as one string?"
Instead of
Expand|Select|Wrap|Line Numbers
  1. document.createElement("object");
you have to write out the whole HTML string (see documentation).
So you would probably write something like:
Expand|Select|Wrap|Line Numbers
  1. document.createElement("<object id=\"...\" width=\"...\" ...>...</object>");
This is incorrect syntax, so won't work in standards-compliant browsers so you could check for the existence of the object and then try this code.
Sep 22 '07 #5
Tarik Monem
63 New Member
OK, with some digging around on the internet and help from the last response, here's the solution:

First, I had to use PHP to detect what browser because I found that javascript can not tell between Opera and Internet Explorer and thereafter direct the browser to the proper Javascript code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE)
  3. {
  4. echo  '
  5.     </head>
  6.     <body onload="javascript:preloading3();javascript:Is();javascript:myEmailListFunc();javascript:myFl_obj_emb_opera();">
  7.     ';
  8. }
  9. else if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
  10. {
  11. echo  '
  12.     </head>
  13.     <body onload="javascript:preloading3();javascript:Is();javascript:myEmailListFunc();javascript:myFl_detect_func();">
  14. <div id="myfldiv">
  15. <span>
  16. </span>
  17. </div>    
  18.     ';
  19. }
  20. else
  21. {
  22. echo'</head><body onload="javascript:preloading3();javascript:Is();javascript:myEmailListFunc();javascript:myFl_detect_func();">';
  23. }
  24. ?>
  25.  
The above code also creates a div called "myfldiv" which I did not want to be created with any other browser other than IE.

The following Javascript code, with respects to Opera, creates an element by writing the entire HTML string exactly as the response above suggested.

Expand|Select|Wrap|Line Numbers
  1. function myFl_obj_emb_opera()
  2. {
  3.     var myfl_div = document.createElement('myfldiv');
  4.     myfl_div.setAttribute('style','position:absolute; left:100px; top:200px; width:640px; height: 560px; background-color: transparent;z-index: 5;');
  5.  
  6.             var myBgDiv = document.getElementById('autismlogo');
  7.             myBgDiv.innerHTML = '';
  8.             myBgDiv.innerHTML = '<img src="images/bg5.jpg" usemap="#bg" border="0" alt="Autism the Musical">';
  9.  
  10.             myfl_div.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase ="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="640" height="560" id="autismIntro" movie="autism_intro3.swf" src="autism_intro3.swf">';
  11.  
  12.             myfl_div.innerHTML += '<param name=\'allowScriptAccess\' value =\'sameDomain\'>';
  13.  
  14.             myfl_div.innerHTML += '<param name=\'movie\' value =\'autism_intro3.swf\'>';
  15.  
  16.             myfl_div.innerHTML += '<param name=\'quality\' value =\'high\'>';
  17.  
  18.             myfl_div.innerHTML += '<param name=\'bgcolor\' value =\'#000000\'>';
  19.  
  20.             myfl_div.innerHTML += '<param name=\'play\' value =\'true\'>';
  21.  
  22.             myfl_div.innerHTML += '<param name=\'id\' value =\'autismIntro\'>';
  23.  
  24.             myfl_div.innerHTML += '<embed src=\'autism_intro3.swf\' quality=\'high\' bgcolor=\'#000000\' width=\'640\' height=\'560\' name=\'autism_intro3\' id=\'autismIntro\' align=\'middle\' allowScriptAccess=\'sameDomain\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'>';
  25.  
  26.             document.body.appendChild(myfl_div);
  27. }
  28.  
However, I could not get this to work with IE, until I did some digging around adobe's web site and found that IE handles flash differently, so the people at macromedia/abode came up with a solution by way of a JavaScript file of their own that you attach to your html/php page, like so:

Expand|Select|Wrap|Line Numbers
  1. <script src="js_files/AC_RunActiveContent.js" type="text/javascript"></script>
  2.  
From there, that allows the "AC_FL_RunConte nt" function to be called, which makes it possible for flash to be played in any version of IE.

Expand|Select|Wrap|Line Numbers
  1. function myFl_obj_emb_ms()
  2. {
  3.     var myfl_div = document.getElementById('myfldiv');
  4.     myfl_div.setAttribute('style','position:absolute; left:100px; top:200px; width:640px; height: 560px; background-color: #000000; z-index: 5;');
  5.  
  6. myfl_div.innerHTML = '<script type="text/javascript">AC_FL_RunContent(\'codebase\',\'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\',\'width\',\'640\',\'height\',\'560\',\'id\',\'autism_intro3\',\'align\',\'middle\',\'src\',\'autism_intro3\',\'quality\',\'high\',\'bgcolor\',\'#000000\',\'name\',\'autism_intro3\',\'allowscriptaccess\',\'sameDomain\',\'pluginspage\',\'http://www.macromedia.com/go/getflashplayer\',\'movie\',\'autism_intro3\' );</script><noscript><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase ="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="640" height="560" id="autismIntro" movie="autism_intro3.swf" bgcolor="#000000" src="autism_intro3.swf">';
  7.  
  8. myfl_div.innerHTML += '<param name=\'movie\' value =\'autism_intro3.swf\'>';
  9.  
  10. myfl_div.innerHTML += '<param name=\'quality\' value =\'high\'>';
  11.  
  12. myfl_div.innerHTML += '<param name=\'bgcolor\' value =\'#000000\'>';
  13.  
  14. myfl_div.innerHTML += '<param name=\'play\' value =\'true\'>';
  15.  
  16. myfl_div.innerHTML += '<param name=\'id\' value =\'autismIntro\'>';
  17.  
  18. myfl_div.innerHTML += '<embed src=\'autism_intro3.swf\' quality=\'high\' bgcolor=\'#000000\' width=\'640\' height=\'560\' name=\'autism_intro3\' id=\'autismIntro\' align=\'middle\' allowScriptAccess=\'sameDomain\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'>';
  19.  
  20.     document.body.appendChild(myfl_div);
  21. }
  22.  
Once the flash file completes it's animation, then it calls a two Javascript functions, one to remove the newly created div and the second to load the home page -- "myhomepage ();"

Here's the remove div function, which (once again) IE did not create the div via createElement function, so I had to use getElementById to select the node to remove it:

Expand|Select|Wrap|Line Numbers
  1. function myfl_obj_emb_remove()
  2. {
  3.     if(navigator.appName == "Microsoft Internet Explorer")
  4.     {
  5.         document.body.removeChild(document.getElementById('myfldiv'));        
  6.     }
  7.     else
  8.     {
  9.         document.body.removeChild(myfl_div);
  10.     }
  11. }
  12.  
Sep 24 '07 #6
Tarik Monem
63 New Member
One update, the latest version of Opera on Mac requires the same technique used with IE for removing the child node.

Which also required that I use PHP to detect Opera and create the div manually as I did with IE.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE)
  3. {
  4. echo  '
  5.     </head>
  6.     <body onload="javascript:preloading3();javascript:Is();javascript:myEmailListFunc();javascript:myFl_obj_emb_opera();">
  7. <div id="myfldiv">
  8. <span>
  9. </span>
  10. </div>    
  11.     ';
  12. }
  13. else if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
  14. {
  15. echo  '
  16.     </head>
  17.     <body onload="javascript:preloading3();javascript:Is();javascript:myEmailListFunc();javascript:myFl_detect_func();">
  18. <div id="myfldiv">
  19. <span>
  20. </span>
  21. </div>    
  22.     ';
  23. }
  24. else
  25. {
  26. echo'</head><body onload="javascript:preloading3();javascript:Is();javascript:myEmailListFunc();javascript:myFl_detect_func();">';
  27. }
  28. ?>
  29.  
  30.  
  31. function myfl_obj_emb_remove()
  32. {
  33.     if(navigator.appName == "Microsoft Internet Explorer")
  34.     {
  35.         document.body.removeChild(document.getElementById('myfldiv'));        
  36.     }
  37.     else if(navigator.appName == "Opera")
  38.     {
  39.         document.body.removeChild(document.getElementById('myfldiv'));
  40.     }
  41.     else
  42.     {
  43.         document.body.removeChild(myfl_div);
  44.     }
  45. }
  46.  
Sep 24 '07 #7
acoder
16,027 Recognized Expert Moderator MVP
Thanks for posting your working solutions.

You've used browser detection which is prone to error. Wherever possible, you should try feature/object detection. I'm not sure if it is possible in this case, but I haven't tested.
Sep 25 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1662
by: Michael Phillips | last post by:
Hello I am trying to use DOM to create an object in a document and wish to be compativle with Opera My code is containerDiv = document.createElement("div"); //create download container div containerDiv.setAttribute("id", "statusContainer");
2
2572
by: Martin Doyle | last post by:
Ok, I'm building a JS-based limitless-sublevel dynamic menu and am making it cross browser as well - 3 packs of aspirin so far and counting ;) I'm having a weird rendering problem using Opera 7.51, even though it displays fine in Mozilla 1.6, Firefox 0.9, Netscape 7.1 and Internet Explorer 6.0 Hope someone can help!
2
2122
by: skubik | last post by:
I'm curious as to whether it's possible to create a Form object and populate it with form element objects, strictly in Javascript, without the need to apply the form to a document. Essentially, I want to do this: tmpFormObj = new Form(); tmpFormObj.target = document.location; // For example. tmpFormObj.method = "POST";
4
2521
by: Howard Jess | last post by:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865), my form disappears from the HTML markup (below). To summarize: 1) In a <script> block in the <head> I create a form element (part of object/feature/bug detection). 2) There's a <form> element defined in the <body>, with the id 'theForm'. 3) The onload function...
7
3249
by: priya.tweety | last post by:
How to call a js file from another js file?
2
13310
by: Eero Tuomenoksa | last post by:
Hi Does someone knows how i can show/hide multible divs at one click? -- Käytössä Operan vallankumouksellinen sähköpostiohjelma: http://www.opera.com/mail/
3
1921
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but enough to get the idea). Here is the code: ----------------------------------------------------------------- <html>
2
2583
by: emma.sax | last post by:
My script is as follows: function setImageSizes() { var staticHeight = 70; if(!document.getElementsByTagName || !document.images) return false; var thumbnail = document.getElementsByTagName("img"); for(var i=0; i<thumbnail.length; i++) { if(thumbnail.className=="thumbnail_img") {
14
5176
RMWChaos
by: RMWChaos | last post by:
Firebug is reporting "too much recursion" when I attempt to create a child element in a parent that doesn't exist yet. The script should automatically create the missing parent before going on to create the child element. At the point where the script is supposed to call itself with the new properties to create the parent, it gives me the error...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.