Soundcloud HTML5 Widget is not loaded, throws error - soundcloud

I am trying to use SoundCloud HTML5 widget.
I want to load the widget and then, through JavaScript, tell it what to play. But when I tried to do this by this code
<script src="http://connect.soundcloud.com/sdk.js"></script>
<iframe id="sc-widget" width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/"></iframe>
<script src="http://w.soundcloud.com/player/api.js" type="text/javascript"></script>
<script>
var widgetIframe = document.getElementById('sc-widget'),
widget = SC.Widget(widgetIframe),
newWidgetUrl = 'http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F1848538&show_artwork=true';
console.log("before load");
widget.load(newWidgetUrl);
console.log("after load");
</script>
all I see in the console is
before load
after load
before load
after load
before load
after load
Unsafe JavaScript attempt to access frame with URL
http://www.karelbilek.com/musicalibre/ from frame with URL
https://w.soundcloud.com/player/. The frame requesting access has a
protocol of 'https', the frame being accessed has a protocol of
'http'. Protocols must match.
and the error
No SoundCloud widget URL was provided
in the widget. Now what am I doing wrong? Why is the console.log run three times, why is nothing loaded and why do I see the error?

OK, I think I get it. The key things:
Something must be loaded in the HTML5 widget beforehand, otherwise it never gets loaded and you can't even reload it. It doesn't matter what it is, but it must be an existent track.
The example here http://developers.soundcloud.com/blog/html5-widget-api is wrong - you should put a track URL as a parameter to widget.load, not the whole w.soundcloud.com... thing.
The revised, working version
<script src="http://connect.soundcloud.com/sdk.js"></script>
<iframe id="sc-widget" width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F1848538&show_artwork=true"></iframe>
<script src="http://w.soundcloud.com/player/api.js" type="text/javascript"></script>
<script>
var widgetIframe = document.getElementById('sc-widget'),
widget = SC.Widget(widgetIframe),
newWidgetUrl = 'http://api.soundcloud.com/tracks/1848538';
console.log("before load");
widget.load(newWidgetUrl);
console.log("after load");
</script>
The errors are still appearing, but they are not really relevant.

Related

Facebook Pixel to track a click on a link

I want to track each time someone clicks on a link on my web (this click makes a file to be downloaded) to optimise my Facebook Ads (pay per conversion). After including the Facebook pixel in the head section of my web, I have to track this event, for example as a "lead", so I'm using this piece of code at the beginning of the body:
<script type="text/javascript">
$( '#link' ).click(function() {
fbq('track', 'Lead');
});
</script>
Please note that "link" is the id I've set for the link:
<a id="link" href="/content/file.zip">press here</a>
However, I'm tracking a "PageView" (because of the first code in the head section), but I'm not tracking the lead event (the click on the link).
I've also tried this one:
<script type="text/javascript">
$("#link").on('click', function() {
fbq('track', 'Lead');
});
</script>
And I've also tried with an onclick event in the link, like this:
press here
<script type="text/javascript">
function fileDownloaded() {
fbq('track', 'Lead');
return true;
}
</script>
Nothing works for me (I've also put the code of the event at the end of the body section). What am I doing wrong?
Thanks a lot.
I've found a solution that works for me, in case is useful for someone else:
Instead of putting the link inside an href, I've moved the link to the javascript function.
I've used an onclick method to call the javascript function in which I first call the Facebook event to track, and then the download of the file starts.
The result is something like this for the HTML (the text I want to link):
<div onclick="fileDownloaded()">press here</div>
And something like this for the javascript function I want to track with Facebook pixel when someone clicks on the link (at the end of the body section):
<script>
function fileDownloaded() {
fbq('track', 'Lead');
window.open("/content/file.zip","_self")
}
</script>
Best regards.
If you put the URL inside javascript, the link will be "dead" for any visitor that doesn't have scripts enabled in their browser.
You can just put fbq() inside a function inside separate script tags like so:
//pixel code above
fbq('track', 'PageView');
</script>
<script>
function Lead(){ fbq('track','Lead'); }
</script>
<body>
Click tracked by FB!
I use this with image;
<a href="https://downloadurl">
<img src="target image" alt="xxx" onclick="fbq('track','Lead')"/>
</a>
this works if you have installed the fb pixel code in the website header.

Aviary HTM5L sample not working in iOS Safari (photo appears to keep loading)

I took the sample HTML5 and tried in iOS Safari.
The sample photo appears but keeps loading continuously and no Aviary editing actions can be performed.
Does anybody have a solution?
Here's the sample code directly from the Aviary site at http://www.aviary.com/web-documentation
<!-- Load Feather code -->
<script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>
<!-- Instantiate Feather -->
<script type="text/javascript">
var featherEditor = new Aviary.Feather({
apiKey: '12345678',
apiVersion: 2,
tools: 'all',
appendTo: 'injection_site',
onSave: function(imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
}
});
function launchEditor(id, src) {
featherEditor.launch({
image: id,
url: src
});
return false;
}
</script>
<div id="injection_site"></div>
<img id="image1" src="http://images.aviary.com/imagesv5/feather_default.jpg"/>
<!-- Add an edit button, passing the HTML id of the image and the public URL ot the image -->
<p><input type="image" src="http://advanced.aviary.com/images/feather/edit-photo.png" value="Edit photo" onclick="return launchEditor('image1', 'http://images.aviary.com/imagesv5/feather_default.jpg');" /></p>
I contacted Aviary at api#aviary.com and they mentioned that there was a bug that they fixed today. It works now.
You have to put this code on live server, local does't seem to work here. Aviary web documentation says that "Set a location on your server for Aviary to send a server-to-server HTTP POST".
Just in case...
You must add the complete 'src' in the photo.
Instead us using "src='/upload/miPhoto.png'" you must use "src='http://localhost:8080/project/upload/miPhoto.png'"
Hope this helps!

Attempting to move around iframe in DOM without refreshing. Chrome's "adoptNode" seems to not be working

Here is the deal (over-simplified a bit)
I'm creating an application which has "tabs", each tab can have similar content displayed as iFrames.
So, I was hoping to share those in between tab switches, since the initial request from the iFrame load is somewhat of an expensive operation.
This, however, would require me to "save" the iframe, and then re-insert on the DOM.
There are two issues with that:
1) I can't seem to be able to access the iframe's contentWindow to call into javascript functions while it's resting in memory
2) The iframe reloads whenever it's inserted in the DOM.
I read that document.adoptNode might fix issue #2, so I tried the following
<html>
<head>
</head>
<body>
<script>
window.onload = function() {
setTimeout(adoptIFrame, 500);
};
var next = ['red', 'blue']
var index = 0;
function adoptIFrame() {
var iFrame = document.adoptNode(document.getElementById("frame"));
document.getElementById(next[index++ % 2]).appendChild(iFrame)
setTimeout(adoptIFrame, 500);
}
</script>
<div id="red" style="width:500;height:500;background-color:red;">
</div>
<div id="blue" style="width:500;height:500;background-color:blue;">
<iframe src="your_url" id="frame"/>
</div>
</body>
But each time, there is a still a refresh being made on re-insertion.
Any ideas?
This is a bit late, but since I've come across the same issue, I did some research and it seems the feature has been removed from Webkit: https://bugs.webkit.org/show_bug.cgi?id=81590.

How to resize a website which appears in an iFrame?

How can we resize a website which appears in an iFrame ? Is it possible if the website is wider than the Facebook page to make it appear a bit smaller so that we can see it all ?
Here is the code I used to avoid the scroll bar at least:
<html>
<head></head>
<body>
<iframe style="width:827px; height:1000px;" src="#"></iframe>
</body>
</html>
Thanks by advance !
Change the height and width for example for my facebook i changed it to
style="border:none; overflow:hidden; width:215px; height:290px;"
Just make sure to add the overflow hidden part so it hides any extra
Use this code just after your opening tag
<div id="fb-root"></div>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID', //Your facebook APP here
cookie : true, // enable cookies to allow the server to access the session
});
}
window.onload = function() {
FB.Canvas.setAutoGrow(91);
}
</script>
also add this css statement to your header section.
<style>
body {overflow:hidden;} /*This is handy for removing horizontal/vertical scrollbars as we won't need them if we autosize; */
</style>

Resizable Iframe for facebook iframe applications

I have an iframe application build up on php.
I have set iframe size as resizable.
There is a problem the display is not proper if the content is too large.
I have applied the code available on http://wiki.developers.facebook.com/index.php/Resizable_IFrame
My xd_receiver.htm file is inside my templates folder where my php files are residing.
The code which I am using is:
<div id="FB_HiddenIFrameContainer" style="display:none; position:absolute; left:-100px; top:-100px; width:0px; height: 0px;"></div>
<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
FB_RequireFeatures(["CanvasUtil"], function(){
FB.XdComm.Server.init(xd_receiver.htm>);
FB.CanvasClient.startTimerToSizeToContent();
}
);
</script>
Please guide on how to make the display correct.
even though In am not sure about this, but Large content could be the the real issue,
try to move this part to the end of your page
FB_RequireFeatures(["CanvasUtil"],
function(){
FB.XdComm.Server.init(xd_receiver.htm>);
FB.CanvasClient.startTimerToSizeToContent();
} ); </script>