including a javascript file in a JS file without using <script> - javascript

I have a piece of JS which more or less looks like this
<script type="text/javascript" src="http://player.script.com/jsapi">
player = new playrer.Player('Yplayer',{
styleid: '0',
client_id: 'YOUR YOUKUOPENAPI CLIENT_ID',
vid: 'Replace the Youku Video ID'
});
</script>
Which would work if I directly drop it into my html document via script tag. But I am trying to call this by including a separate global javascript file. Can I avoid including the remote .jsapi via the <script>

a solution will be using jquery getScript() function
$.getScript( "http://player.script.com/jsapi", function( data, textStatus, jqxhr ) {
player = new playrer.Player('Yplayer',{
styleid: '0',
client_id: 'YOUR YOUKUOPENAPI CLIENT_ID',
vid: 'Replace the Youku Video ID'
});
});

You shouldn't use both the src attribute and javascript code (body content) inside the same tag.

As others have commented, the "jsapi" script will execute, but ignore your local javaScript. You need:
<script type="text/javascript" src="http://player.script.com/jsapi"></script>
<script type="text/javascript">
player = new playrer.Player('Yplayer',{
styleid: '0',
client_id: 'YOUR YOUKUOPENAPI CLIENT_ID',
vid: 'Replace the Youku Video ID'
});
</script>
You can put the embedded script in another file if you wish

Related

Unable to embed google plus posts

I am trying to embed google plus posts in my application.
I have loaded platform.js file in header
<script>
window.___gcfg = {
lang: 'en-US',
parsetags: 'onload'
};
</script>
<script src="https://apis.google.com/js/platform.js" async defer>
</script>
<script>
function renderWidget() {
gapi.post.render("widget-div", {'href' : 'https://plus.google.com/109813896768294978296/posts/hdbPtrsqMXQ'} );
}
</script>
In html page
Render the embedded post
<div id="widget-div"></div>
When I clicked on the link, it shows nothing. Is there anything to be added. Here is the reference i followed https://developers.google.com/+/web/embedded-post
You might be opening HTML file directly in browser, which could be problem in some browser(s) (i.e. In Google Chrome. You can verify the issue here).
Try running it using a local-server(XAMPP maybe) so the URL will look similar to http://localhost/yourpath/test.html
Hope this helps!!

How to use SmartyStreets LiveAddress Plugin with dynamically loaded form

I am trying to get the LiveAddress website plugin to work in a Wordpress website. The form is loaded dynamically via javascript.
It seems that the form is not visible to the plugin at the time the plugin loads.
The plugin shows the following message in the javascript console:
NOTICE: No matches found for selector #field_96764599. Skipping...
The form I am trying to use is generated by Podio (podio.com), but I have tried the same without success using a form hosted by jotform.com. If I copy the HTML of the form and paste it on the page, it works. The problem happens when the form is loaded via javascript.
Can someone see what I am doing wrong? Thanks.
<!-- BEGIN Podio web form -->
<script src="https://podio.com/webforms/12651261/927644.js"></script>
<script type="text/javascript">
_podioWebForm.render("927644")
</script>
<noscript>
Please fill out the form
</noscript>
<div class="podio-webform-container">
A webform by Podio
</div>
<!-- END Podio web form -->
<script src="//d79i1fxsrar4t.cloudfront.net/jquery.liveaddress/2.8/jquery.liveaddress.min.js"></script>
<script type="text/javascript">
var ss = jQuery.LiveAddress({
key: 'HERE IS WHERE I PUT MY KEY',
waitForStreet: true,
debug: true,
addresses: [{
street: '#field_96764599'
}]
});
</script>
I know this is a bit late but have you tried using .ready() with jQuery?
<script type="text/javascript">
$( document ).ready(function() {
var ss = jQuery.LiveAddress({
key: 'HERE IS WHERE I PUT MY KEY',
waitForStreet: true,
debug: true,
addresses: [{
street: '#field_96764599'
}]
})
});

Use flash var grabbed by another function JS

so this is what I need to do. So this function is called when the Flash video recorder on the page saves the video:
function onSaveOk(streamName,streamDuration,userId,cameraName,micName,recorderId){
//alert("onSaveOk("+streamName+","+streamDuration+","+userId+","+cameraName+","+micName+")");
//the user pressed the [save] button inside the recorder and the save_video_to_db.XXX script returned save=ok
//recorderId: the recorderId sent via flash vars, to be used when there are many recorders on the same web page
$('#record').hide();
$('#jwplayer').show();
}
I then have my JWplayer script that I would like to use the streamName flash var. Here is my JWPlayer script with my current attempt:
<div id="jwplayer">
<center>
<div id='mediaplayer'></div>
<script type="text/javascript">
jwplayer('mediaplayer').setup({
'flashplayer': 'jwplayer/player.swf',
'id': 'playerID',
'width': '640',
'height': '580',
'provider': 'rtmp',
'streamer': 'rtmp://domain/recorder/_definst_',
'file': 'onSaveOk("+streamName+")'
});
</script>
</center>
This is where I try to use the flash var,
'file': 'onSaveOk("+streamName+")'
As it is like that, it does not work, could someone show me the correct way to do this? Thanks.
This site makes understanding and implementing a flash var as no-brainer as it gets.
Copy and paste code:
http://www.justthecodeplease.com/category/urls-flashvars/

jwplayer streaming m3u from another domain

Looking to stream a radio station on my website, we also host the streaming but from a different domain.
Just getting this error:
Task Queue failed at step 5: Playlist could not be loaded due to crossdomain policy restrictions
Code on domain A:
<div id="mediaplayer">Loading...</div>
<script type="text/javascript" src="/jwplayer/jwplayer.js"></script>
<script type="text/javascript">
jwplayer("mediaplayer").setup({
flashplayer: "/jwplayer/player.swf",
playlistfile: "http://domainB/stream.m3u",
image: "/images/listening.jpg",
type: "sound",
allowscriptaccess:"always",
width:300,
height:300
});
</script>
Just having no luck, tried a variety of options...
Am I wasting my time with out crossdomain.xml on domain B ? (of which I have no access to at the moment, but maybe able to get access to soon)
The stream works fine from itunes, winamp etc..
Okay, the problem was:
The url for the m3u file isn't the actual url for the stream.
I needed to open the m3u file in a text editor, and use that url, which included port etc.
<script type='text/javascript' src='/jwplayer/jwplayer.js'></script>
<div id='media'></div>
<script type='text/javascript'>
jwplayer('media').setup({
'flashplayer': '/jwplayer/player.swf',
'file': 'http://xx.xxxxxx.xxx:80/xxxxfm',
'provider': 'sound',
'controlbar': 'bottom',
'image': "/images/listening.jpg",
'width': '300',
'height': '300'
});
</script>
this code seems to work, no crossdomain.xml needed, it was requesting one only because the url was incorrect.

safari displays javascript source instead of executing

i have a web application that has javscript interspersed through the page. What happens is that safari will dump the source of the javascript code instead of executing it. I can reproduce this consistently.
The page is a mashup of different forms of content:
it loads flash videos using osflv and is generated via a php script on the server side. In addition the page also contains calls to Google Map's API to display a map. The content is placed in separate tabs using javascript to provide tab interaction.
I am also using mootools, and not sure if that is potentially causing issues.
Here are the javascript includes:
<script type="text/javascript" src="/js/mootools-1.2.1-core.js"></script>
<script type="text/javascript" src="/js/mootools-1.2-more.js"></script>
<script type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="/js/sifr.js"></script>
<script type="text/javascript" src="/js/sifr-debug.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/alerts.js"></script>
<script type="text/javascript" src="/js/swfobject.js"></script>
<script type="text/javascript" src="/js/autocompleter.js"></script>
<script type="text/javascript" src="/js/observer.js"></script>
<script charset='ISO-8859-1' src='/js/rac.js' language='javascript'></script>
rac.js comes from osflv, common.js and alerts.js are custom javascript code that includes custom classes and functions used to either display or manipulate data in the page.
This block of code executes in the page just fine:
<script type="text/javascript">
var whitney = { src: '/flash/whitney.swf'};
sIFR.activate(whitney);
sIFR.replace(whitney, { selector: 'h6#propertyHeadline', wmode:'transparent',css: {'.sIFR-root': {'color': '#1ca9b9' }}});
</script>
This code also executes just fine:
<script language='javascript'>
var src = '/player';
if(!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0))
src = 'player8';
AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', 'width', 520, 'height', 440, 'src', src, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'id', 'flvPlayer', 'allowFullScreen', 'true', 'movie', src, 'FlashVars','movie=media/orig/4b845109d99d0.flv&fgcolor=0x1CA9B9&bgcolor=0x000000&autoload=off&volume=70');
</script>
This is the final snippet of code that is embedded in the html towards the bottom of the page before the end of the body tag, Safari will randomly spit out the src code in the browser at any point beyond the good maps script include:
<script src="http://maps.google.com/maps?file=api&v=2&key=googlemapsapikeyblockedout" type="text/javascript"></script>
<script type="application/javascript">
function InitPropertyDashboardTabs(){
mytabs = new TabPanel('DashboardTabPanel');
initializeGallery();
initializeSiteplan();
initializeMap('address blocked out');
}
var map = null;
var geocoder = null;
function initializeSiteplan()
{
var flashvars = {PropertyId:1,BasePath:'/',wmode:'transparent'};
var params = {wmode: 'transparent'};
var attributes = {id: 'SWFSitePlan',name: 'SWFSitePlan'};
swfobject.embedSWF("/flash/FloorplanViewer/FloorplanViewer.swf", "SiteplanFlash", "915", "500", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}
function initializeGallery()
{
var params = {wmode: 'transparent'};..... (more code)
This is what the page with the js dump
(source: oxid8.com)
this is what the page should look like:
(source: oxid8.com)
First, you shouldn't use the language attribute, it's deprecated.
The only thing I can see is that you use application/javascript instead of text/javascript in your HTML (there's a difference between what you specify in your HTML and the MIME-type servers use when sending a Javascript file), but I cannot reproduce any errors on Chromium/Linux with a simple test case like
<!DOCTYPE html>
<html>
<head>
<title>dkdkd</title>
</head>
<body>
<script type="application/javascript">
var i=0;
</script>
</body>
</html>
(Perhaps you can try this, too.)
Just in case: is the script element closed properly? Is all Javascript correct, i.e. does it pass JSLint?
Perhaps you can paste the full source of the HTML page (preferably on something like Pastebin), so we can have a closer look.
I guess I'll give this a shot. I was having a similar problem on some pages that used TinyMCE (javascript or even parts of my html were being displayed on the page)
MY solution was to upgrade the version of TinyMCE that I was using. v3.3 has an overhauled Webkit handler.
The issue so far as I can tell was that TinyMCE was injecting (poorly) additional blocks of javascript into the page.
This (and a handful of similar blocks) is always injected into <head>
<script type="text/javasript" src="http://www.example.com/javascript/rte/langs/en.js" onload="tinemce.dom.ScriptLoader._onLoad(this,'http://www.example.com/javascript/rte/langs/en.js', 0);">
Which, when onload fired, injected the following block into a random location in the DOM, mangling whatever it was placed on top of.
<script type="javascript" src="http://www.example.com/javascript/rte/langs/en.js">
The result of that, as seen in the Webkit Developer Tools was to turn
<td class="tab" nowrap="">
into:
<td class="ta<script stype="text=""javascript"" src="http://www.example.com/javascript/rte/langs/en.js"> "b" nowrap=>"
Since that's clearly not valid markup the resulting garbage was output.
Upgrading my install of TinyMCE from the previous stable to v3.3rc1 fixed the issue.TinyMCE Changelog references a total Webkit overhaul.
edit: By random I really mean random. It inserts the script tag in a different location each time, sometimes breaking content, sometimes not.

Categories

Resources