Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2012, 06:39 PM   PM User | #1
dposthuma
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
dposthuma is an unknown quantity at this point
onclick="load(url)" into iframe issue

I have a client that has 15 unique movies, each must be dynamically loaded into an iframe created within the webinar page using the click of a text-link. I am trying to use the onclick event, but when multiple movies are listed, the code wants to load only the first movie listed. The code for a single movie currently looks like...

Code:
<script type="text/javascript">

function load(file){
var iframeTag = document.getElementById('frame');
var body = document.getElementsByTagName('body').item(0);
var myiframe = document.getElementById('myiframe');
if(iframeTag) body.removeChild(iframeTag);
iframe = document.createElement('iframe');
iframe.src = file; 
iframe.id = 'frame';
iframe.width = '960px';
iframe.height = '720px';
iframe.frameborder = '0';
iframe.scrolling = 'no';
myiframe.appendChild(iframe);
} 
                        </script>
                  <a onclick="load('unique movie url'); return false">Load Movie </a></p>
How can I configure the code so that I will have 15 separate "Load Movie" links, each able to load its own unique movie into the iframe that is generated? Similarly, I would guess I would need to "unload" previous movie urls before another one could be loaded???

Thanks in advance for any help you can offer...I am stumped.
dposthuma is offline   Reply With Quote
Old 09-22-2012, 04:08 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Hope your not trying to do this with one button. 15 movies, 15 buttons or a select dropdown with 15 options. Then send the url with each button.
sunfighter is offline   Reply With Quote
Old 09-22-2012, 05:13 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
why not just hardcode the iframe and change the src onclick?

Code:
<body>
<iframe id="frame" width = '960px' height = '720px' height = '720px' frameborder = '1' scrolling = 'no'></iframe><br>
<script type="text/javascript">

function load(file){
document.getElementById('frame').src=file+"?autoplay=1";
} 
</script>
<a href="#" onclick="load('http://www.youtube.com/embed/XmxaPKt94jI'); return false">Load Movie 1</a>
<a href="#" onclick="load('http://www.youtube.com/embed/Ns7Z8ag4oSY'); return false">Load Movie 2 </a>
<a href="#" onclick="load('http://www.youtube.com/embed/yv0zA9kN6L8'); return false">Load Movie 3 </a>
				  
</body>
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
dposthuma (09-24-2012)
Old 09-24-2012, 03:34 PM   PM User | #4
dposthuma
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
dposthuma is an unknown quantity at this point
Thanks, that worked fine. I guess I was making it more complicated than it needed to be.
dposthuma is offline   Reply With Quote
Old 01-25-2013, 07:54 PM   PM User | #5
bigirl
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bigirl is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
why not just hardcode the iframe and change the src onclick?

Code:
<body>
<iframe id="frame" width = '960px' height = '720px' height = '720px' frameborder = '1' scrolling = 'no'></iframe><br>
<script type="text/javascript">

function load(file){
document.getElementById('frame').src=file+"?autoplay=1";
} 
</script>
<a href="#" onclick="load('http://www.youtube.com/embed/XmxaPKt94jI'); return false">Load Movie 1</a>
<a href="#" onclick="load('http://www.youtube.com/embed/Ns7Z8ag4oSY'); return false">Load Movie 2 </a>
<a href="#" onclick="load('http://www.youtube.com/embed/yv0zA9kN6L8'); return false">Load Movie 3 </a>
				  
</body>
Hi xelawho,

I like your approach to this issue. Would you have an idea of the code needed if I wanted an external link to load the page with Movie 2 playing?

Thank you!
bigirl is offline   Reply With Quote
Reply

Bookmarks

Tags
iframe, load, onclick, unload

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:50 PM.


Advertisement
Log in to turn off these ads.