473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

FireFox Hates My Simple Code

Expand|Select|Wrap|Line Numbers
  1. function flash_insert()
  2. {
  3.   var flash_to_insert = '<object type="application/x-shockwave-flash" data="myflash.swf" width="980" height="130">';
  4.   flash_to_insert = flash_to_insert + '<param name="movie" value="myflash.swf" />';
  5.   flash_to_insert = flash_to_insert + '</object>';
  6.  
  7.   document.getElementById('flash_2').innerHTML = flash_to_insert;
  8. }
  9.  
  10. .
  11. .
  12. .
  13.  
  14. <span id="flash_2"></span>
Hey y'all,

The code above works fine in IE7, Opera9, but NOT in Firefox. Why??

Thanks in advance.
Sep 11 '08 #1
8 1249
acoder
16,027 Expert Mod 8TB
Any errors?

If you include the HTML directly without JavaScript, does it work?
Sep 11 '08 #2
Any errors?

If you include the HTML directly without JavaScript, does it work?
No errors in the (FF) console. The HTML content in the variable works when directly included in the HTML document.

The code works as expected in IE7 and Opera9, and what is interesting is that I suspect that the javascript is also working in FF, as there are no errors.

For example;

Expand|Select|Wrap|Line Numbers
  1. function flash_insert()
  2. {
  3.   var flash_to_insert = '<br /><a href="javascript:flash_insert();">hello</a>';
  4.  
  5.   document.getElementById('flash').innerHTML = flash_to_insert;
  6. }
or;

Expand|Select|Wrap|Line Numbers
  1. function flash_insert()
  2. {
  3.   var flash_to_insert = '<p>hello</p>';
  4.  
  5.   document.getElementById('flash').innerHTML = flash_to_insert;
  6. }
will work in all browsers, but this;

Expand|Select|Wrap|Line Numbers
  1. function flash_insert()
  2. {
  3.   var flash_to_insert = '<object type="image/gif" data="../images/frvcc.gif" style="width:98px; height:98px;">';
  4.   flash_to_insert = flash_to_insert + '</object>';
  5.  
  6.   document.getElementById('flash').innerHTML = flash_to_insert;
  7. }
won't work in FF. It seems as though FF won't show content associated with the <object> tag when inserted by JS.

This may not be a javascript problem after all, but more likely a FF issue.

Sorry if I'm in the wrong forum.
Sep 11 '08 #3
acoder
16,027 Expert Mod 8TB
Instead of using innerHTML, have you tried document.createElement("object") and setting attributes/children and appendChild()?
Sep 11 '08 #4
Instead of using innerHTML, have you tried document.createElement("object") and setting attributes/children and appendChild()?
AHA!! Yes, that works. I forgot that my web docs are being served by PHP, which by the way, as you know, can serve different header info to different browsers. I'm serving XHTML1.1 to FF, Opera and any other browser that can handle 'Content-Type: application/xhtml+xml'. IE cannot handle this type of doc, as I understand, so it is being served 'Content-Type: text/html.'

Now the javascript is not working for IE. Is it because IE cannot treat the doc as XML?

What can I do?

Thanks for your help, acoder.
Sep 11 '08 #5
Maybe the code is the problem.

Expand|Select|Wrap|Line Numbers
  1. function flash_insert()
  2. {
  3.   var flash_to_insert = document.createElement('object');
  4.  
  5.   flash_to_insert.setAttribute('type','image/gif');
  6.  
  7.   flash_to_insert.setAttribute('data','../images/frvcc.gif');
  8.  
  9.   flash_to_insert.setAttribute('style','width:98px;height:98px;');
  10.  
  11.   document.getElementById('flash').appendChild(flash_to_insert);
  12. }
Sep 11 '08 #6
acoder
16,027 Expert Mod 8TB
IE unfortunately uses its non-standard createElement - see link. If you specify the whole HTML string, it'll work. Ugly!
Sep 11 '08 #7
A sincere thanks to you, acoder, for pointing me in the right direction.

I've read the article from the link and it does seem a little ugly.

Since I usually serve up web pages with PHP, I decided to look for a solution using PHP.

What I did was to create code in PHP that selects a set of javascript code to be used when serving HTML, and a different set of javascript code when serving XHTML. Very little extra PHP was needed to link to the proper javascript file, but it did involve writing twice the amount of javascript to accomodate both scenarios.

UGLIER??

It works though, and it seperates the crossbrowser issues I've been having nicely, without much extra machine-cycle or (JS) file download time.

I can now;

1. Serve a web doc (HTML or XHTML, depending on the client) with flash content, without the 'Click to activate and use this control' pop-up, seen in Opera9.

2. Replace flash content dynamically on a web doc whether served-up as HTML or XHTML.

Being a rookie, I feel that I may have reinvented the wheel for no-good reason and there may be an easier solution out there.

Please comment on my rant.

Thanks again, acoder.
Sep 11 '08 #8
acoder
16,027 Expert Mod 8TB
In my haste, I forgot about SWFObject (formerly FlashObject). That should handle all the cross-browser issues for you.

PS. just noticed what your user handle spells. Nice! :D
Sep 11 '08 #9

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

Similar topics

4
by: Perion | last post by:
I have a simple form with, among other things, an ADODC data control (called "Adodc1"). The ADO connection to the database tests fine but when I try to add code to any of the Adodc1 control's event...
7
by: Tony LaPaso | last post by:
Hi All, I have a simple style sheet example below and I'm seeing different results in IE 6 vs. Firefox 1.0.3. I'm not sure which browser is rendering it correctly but I'm tending to think it's...
45
by: Pat | last post by:
its seems asp.net validation doesn't fire when using FireFox? Tested a page and it doesn't fire. It seems the javascript doesn't fire Any ideas?
35
by: Aaron Gray | last post by:
Hi, I have some code I just cannot seem to get to work properly on FireFox. It is probably something simple. On FireFox the following code does not seem to terminate in the browser, but it...
10
by: Paul Gorodyansky | last post by:
Hi, Ran into the problem today - in INPUT field Firefox executes clean-yp of the content if a user presses Esc, _before_ control goes to the code via onkeydown - and search showed that it's a...
9
by: WebMatrix | last post by:
I've been developing ASP.NET 1.1 application, testing it in IE 6.0 on my development machine. Of course, everything looks normal in IE as it should. Well, since it's going to be released to...
1
by: richardscheff | last post by:
Video selector works for IE but not other browsers. for not IE <object ID='Player' data="video/dodgeball.wmv" type="video/x-ms-wmv" width="320" height="280"> <param name="filename"...
7
by: 80s.arcade | last post by:
Hi. Please take a look at this page: http://tinyurl.com/s2l8w In IE6, putting the mouse on each of the two items highlights the word in a blue (different image) and shows a tool tip. In...
9
by: johnd126 | last post by:
I have a cgi program which outputs a fairly hefty amount of html/javascript for doing a complex slide show sorta thing in a variety of areas in the browser. I accomplish this by creating a series...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.