473,414 Members | 1,674 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,414 software developers and data experts.

Using JavaScript to change <object> tag attributes

I'm trying to build a simple gallery using some thumbnail images to load larger images and SWF files by swapping out the source hrefs. It works okay with images, but I'm having trouble doing the same thing with SWFs (Note: Both galleries exist on separate pages so there is no confusion.) Here is the function that works on the image gallery page:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function showPic (whichpic) 
  3. {
  4.  if (document.getElementById) 
  5.     {
  6.           document.getElementById('placeholder').src = whichpic.href;
  7.         }
  8. return false;
  9. }
  10.  
I tried adapting it for the Flash gallery page like this (Note: In preview post, I'm seeing a big space on line 6 between the 'mo' and 'vie' in after setAttribute. This is a weird formatting error that caused by the forum, and doesn't exist inside my code.):

Expand|Select|Wrap|Line Numbers
  1. function showFlash (whichFlash)
  2. {
  3.     if(getElementByID)
  4.     {
  5.         document.getElementByID('placeholder').data = whichFlash.href;
  6.         document.getElementById('swfsrc').setAttribute('movie', whichFlash.href);
  7.     }
  8. return false;
  9. }
  10.  
I'm implementing my SWFs using the Flash Satay method which strips out the embed tag because it's not W3C compliant.

Expand|Select|Wrap|Line Numbers
  1. <object
  2.         id="placeholder"
  3.     type="application/x-shockwave-flash" 
  4.         data="../media/dresscat.swf"
  5.     width="700" height="300">
  6.         <param name="movie" value="../media/dresscat.swf" id="swfsrc" />
  7. </object>
  8.  
Thumbnail link that calls the function:
Expand|Select|Wrap|Line Numbers
  1. <a onclick="return showFlash(this)" href="../media/mia_flash_gallery.swf">image</a>
  2.  
What I want to happen:

When the thumbnail is clicked, the SWF with the ID 'placeholder' should be replaced with the SWF referenced in the thumbnail link, so the old SWF file is "swapped" for the new one.

What actually happens:

When the thumbnail is clicked, a page containing only the SWF is loaded in full frame.

Here's an example of the working image gallery on my site.
Thanks in advance.
Aug 14 '08 #1
3 4217
acoder
16,027 Expert Mod 8TB
Add a return false in the showFlash function otherwise the link href URL will be followed.
Aug 14 '08 #2
Add a return false in the showFlash function otherwise the link href URL will be followed.
Thanks, I actually already had that in there, but for some reason I omitted it when I posted.
Aug 14 '08 #3
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. if (getElementByID)
should be
Expand|Select|Wrap|Line Numbers
  1. if (document.getElementById)
and JavaScript is case-sensitive so it's a small 'd', not ID.
Aug 14 '08 #4

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

Similar topics

3
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle...
3
by: JayBrahms | last post by:
Hi there. OK, this is a little bit complicated. I would live to find a different way to do this, but evidentially I am not able to open a Text-File in JAVASCRIPT and fill an Array with the...
2
by: trusst_3 | last post by:
Hello, This is the only line in my entire code that does not validate in XHTML : <td width="24" bgcolor="#330066" onclick="javascript:color1()" class="borderWidthr"></td> However, it is...
23
by: Andrew Thompson | last post by:
This is intended to fix a long standing (cough)Java(cough) problem with which I'm sure some of you will be familiar. Sun recommends using the <OBJECT>/<EMBED> elements to cater for Java...
1
by: chotiwallah | last post by:
this is the html: <a href="Javascript:change();">change</a> <object data="a.htm" type="text/html" width="200" height="200" id="obj"></object> and this the javascript:
7
by: Simon Strandgaard | last post by:
There are no <iframe> tag in xhtml strict, instead I should use <object>. If I change <iframe> to <object> then my javascript stops working. I am curious to how to use <object> with javascript...
6
by: Christopher Benson-Manica | last post by:
(I posted this as a reply to my thread about iframes, but I think it may get mostly ignored there.) http://ataru.gomen.org/files/test.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
0
by: laurac | last post by:
Hi, I'm new to JavaScript so I apologize in advance if I ask an obvious or an impossible question. I'm trying to build a simple gallery using some titles/text to load large images and some SWF...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.