473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using JavaScript to change <object> tag attributes

2 New Member
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 4227
acoder
16,027 Recognized Expert Moderator MVP
Add a return false in the showFlash function otherwise the link href URL will be followed.
Aug 14 '08 #2
etabetapi
2 New Member
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 Recognized Expert Moderator MVP
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
9819
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 of the screen that initially comes up with a gif image of a house: <!-- start "house" layer definition for center of screen --> <DIV id="house"...
3
1616
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 Values, so I have to do it this way. I am doing the following: I use a File called "ApplicationResources.properties" containing 2 columns
2
5071
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 valid HTML,since I've defined the function color in the javascript section of the <head> tag.
23
2258
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 applets, but then uses *browser* *sniffing* Javascript to select between them. I was hoping to find/create a script that
1
9080
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
2809
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 ? <?xml version="1.0" encoding="ISO-8859-1"?>
6
2790
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" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>&lt;object&gt; test</title>
0
1104
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 files by swapping out the source hrefs. It works okay with only images, but I'm having trouble when it comes to load the SWFs. I do not know if it's...
0
7736
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
7982
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
7500
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
7827
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
6066
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3514
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...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.