Open object in new window - javascript

I'd like to open a SoundCloud player in a new window when a user clicks a link. Below is an example:
<object height="220" width="220"><param name="movie" value="https://player.soundcloud.com/player.swf?url=https%3A//api.soundcloud.com/tracks/124173519&color=ff5500&auto_play=false&player_type=artwork"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" width="220" height="220" src="https://player.soundcloud.com/player.swf?url=https%3A//api.soundcloud.com/tracks/124173519&color=ff5500&auto_play=false&player_type=artwork" type="application/x-shockwave-flash"></embed></object>
I've tried various tricks, but to no avail. If a user could point me in the right direction, it would be greatly appreciated.

Create something like: <a href='javascript:window.open("page.html")' target="_blank" >link</a> where you include the <object ../> tag in 'page.html'.

if you can dynamically generate the object with a complete html, you can use javascript:
window.open(URL,name,specs,replace)
Example of Server side script:
//playsound.php
<html>
<head>
.....
</head>
<body>
......
<object height="220" width="220"><param name="movie" value="https://player.soundcloud.com/player.swf?url=https%3A//api.soundcloud.com/tracks/124173519&color=ff5500&auto_play=false&player_type=artwork"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" width="220" height="220" src="https://player.soundcloud.com/player.swf?url=https%3A//api.soundcloud.com/tracks/124173519&color=ff5500&auto_play=false&player_type=artwork" type="application/x-shockwave-flash"></embed></object>
</body>
</html>
So if a user clicks on the link in the main window, another window pops up to play the media. I hope this helps

Related

Play youtube video with explicit control

I am trying to play youtube video in a html page with a custom play button like this fiddle.
HTML
<button id="btn">Play</button>
<object type="application/x-shockwave-flash" id="yt" data="http://www.youtube.com/v/6eK-W32IME0?fs=1&enablejsapi=1&hl=en_US" width="330" height="200"><param name="allowScriptAccess" value="always"/></object>
JavaScript
var yt = document.getElementById("yt");
document.getElementById('btn').onclick = play;
function play() {
yt.playVideo();
}
The code works fine in JSFiddle, but when I put same thing in a text file and execute, the video is not playing. Please suggest me in this regard, Thanks in advance.
In the code, you are trying to access element via document.getElementById, which depends on where you write the <script> tag. Fiddle's script loading process or location may be different from normal browsers. As per your code, if the <script> tag is before <button>, then it will not work, where as if you put <script> after <object>, then it will work.
I modified your code as below which i was able to run successfully.
<html>
<head>
<script type="text/javascript">
function init() {
var yt = document.getElementById("yt");
document.getElementById('btn').onclick = play;
}
function play() {
yt.playVideo();
}
</script>
</head>
<body onload="init()">
<button id="btn">Play</button>
<object type="application/x-shockwave-flash" id="yt"
data="http://www.youtube.com/v/6eK-W32IME0?fs=1&enablejsapi=1&hl=en_US"
width="330" height="200">
<param name="allowScriptAccess" value="always"/>
</object>
</body>
</html>
Page has to be loaded via http protocol because of SOP reasons, browser will not allow access to player if loaded as file protocol

How To Add Video To 3D Cube via HTML5

im trying to replace a 3D cube with images with video to add on each face, I'm having problems trying to figure out how to replace the html tag with a html video element tag..
My jsfiddle can be seen below
http://jsfiddle.net/sean3200/W4pGa/
Here's the beginning of the code where the image is being created...
function start3d(texture_image) {
var screen_canvas = document.getElementById('canvas');
Here is the bottom of my code where the image is being loaded
var img = new Image();
img.onload = function() { start3d(img); };
img.src = 'http://content.bitsontherun.com/thumbs/3XnJSIm4-640.jpg';</script>
I know on how to create and load a video via html5 but puting it on each cube is a bit different.. any help on this would be appreciated!! thanks
Put this code inside your div
<object width="400" height="400"><param name="movie" value="http://www.youtube.com/v/YLorLVa95Xo?fs=1&hl=en_GB&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YLorLVa95Xo?fs=1&hl=en_GB&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="400"></embed></object>
or use javascript to set videeo on second div of cube class if you have it in html body:
$('.cube > div').eq(1).html('<object width="360" height="360"><param name="movie" value="http://www.youtube.com/v/YLorLVa95Xo?fs=1&hl=en_GB&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YLorLVa95Xo?fs=1&hl=en_GB&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="360"></embed></object>');
It is working fine in chrome, If it works in safari and firefox, please reply back.

Javascript changing Attribute value from another HTML file

I have a little site, not yet online but that doesn't matter. Inside I have two frames:
<html>
<frameset border="transparent" cols="63%,37%">
<frame src="A.html" name="A" NORESIZE>
<frame src="B.html" name="B" NORESIZE>
</frameset>
</html>
In frame A there is a button.
<html>
<body>
<input onClick="#" type="button"/>
</body>
</html>
In frame B there is a youtube video:
<html>
<body>
<object id="obj" name="obj" width="100%" height="100%">
<param id="param" name="movie" value="http://www.youtube.com/url"/>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"/>
<embed id="embed" name="embed" src="http://www.youtube.com/url"" type="application/x-shockwave-flash" width="100%" height="100%" allowfullscreen="true"/>
</object>
</body>
</html>
Now I'm trying to let the embed's source and the parameter's (named movie) value change into another url. I've tried a lot of codes. The following Javascript codes, for example, won't work:
top.frames["B"].document.getElementById("movie").value = 'http://www.youtube.com/otherurl';
top.frames["B"].document.getElementById("embed").src = 'http://www.youtube.com/otherurl';
So if anyone know how to do these codes right or how to get the same result with other codes, I'd really appreciate it.Anticipated thanks, VVW.
Your DOM is broketh:
Change <param id="param" name="movie" value="http://www.youtube.com/url"
to .. <param id="param" name="movie" value="http://www.youtube.com/url" />
From the parent you can't access nor manipulate elements in the child frame, it's a security measure, otherwise it would be easy to come out with malicious sites that wrap banking sites in iframes and the parent would read the password that you enter into it.
Don't do frames.
Use the YouTube JavaScript Player API. Call player.loadVideoById(). Make sure your original src URL contains &enablejsapi=1:
top.frames["B"].document.getElementById("embed").loadVideoById(id);
Thanks to anyone who answered. I experimented a bit with all of the codes and my result is actually very simple.
top.frames["divtest"].document.getElementById("embed").setAttribute('src','http://www.youtube.com/v/lPMx86wXaKY?version=3&hl=nl_NL');
top.frames["divtest"].document.getElementById("param").setAttribute('value','http://www.youtube.com/v/lPMx86wXaKY?version=3&hl=nl_NL');
I wonder why I didn't come up with that earlier so I appologise to everyone and thank you all for all the help.
VVW

Calling Javascript functions from flash

i need help calling a javascript function from flash, i have embedded the flash using swfobject, heres my javascript to embedd it
<script type="text/javascript">
swfobject.registerObject("myFlashContent", "9.0.0", "expressInstall.swf");
</script>
Here is my HTML which is used to show the flash
<div class="flash">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="258" id="myFlashContent">
<param name="movie" value="btnDemo.swf" />
<param name="allowscriptaccess" value="always" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="btnDemo.swf" width="258">
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
And in my flash i have, which should display a popup message
getURL("javascript:alert('hello')");
However, none of this is working.
Anyone have any ideas as to why this isn't working?
You should really use ExternalInterface for doing calls to JavaScript. Using it looks like this:
import flash.external.ExternalInterface;
if(ExternalInterface.available) ExternalInterface.call('alert','hello');
Using the availability test prevents the code throwing an error when running in the IDE.
Also, in your example you are targeting FP9, so your code must be AS3? AS3 has no getURL() method.

jQuery - Java Pre Roll AD over Flash from CPMStar giving issues in IE Only

My Site is: http://butplaygames.com
Here is the code i am putting in my footer right before the body tag:
<script type='text/javascript'>
<!--
(function(i,w,d,p,c,e,s,t){t=d.getElementsByTagName('script');if(!w[i]){w[i]={ads:[]};s=d.createElement('script');s.src='http'+(d.location.protocol=='https:'?'s://server':'://cdn')+'.cpmstar.com/cached/js/global_v100.pack.js';s.type='text/javascript';s.async='';t[0].parentNode.insertBefore(s,t[0]);}
p['poolid'] = myidherewhichiput;
c['background'] = null;
c['close'] = null;
c['type'] = 'game';
w[i].ads.push({params:p,config:c,events:e,overlay:-1,s:t[t.length-1]});})('cpmstar',window,document,{},{},{});
//-->
</script>
My game embed code for flash:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="800" height="600" id="TreasureTrash">
<param name="movie" value="MYURL" />
<embed src="MYURL" allowfullscreen="true" allowScriptAccess="always" wmode="opaque" width="800" height="600" name="TreasureTrash" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
<param name="allowfullscreen" value="true" />
<param name="wmode" value="opaque">
</embed></object>
The code works in Firefox, Chrome and Opera. But not in IE. Kindly help. I am very lost here. My site is butplaygames.
An AD is supposed to show over my flash games using the javascript code. It shows in Opera, Firefox and Chrome. But does not show in IE. IE does not even show any errors. It just makes the entire swf into a small dot and does nothing.
The script needs to read the .swf from the src atribute. In your case, in the src atribute there is no .swf there.

Categories