I need to append the following HTML fragment into a document, substituting a value for the display_spinner param:
<script type="text/javascript" src="http://public.tableausoftware.com/javascripts/api/viz_v1.js"></script>
<div class="tableauPlaceholder" id="tableauPlaceholder" style="visibility:hidden;width:654px; height:1469px;background-image: url('http://tableau.russellchristopher.org:81/Background.gif'); top: 0px; left: 0px; width: 100%; margin-left: 76px;">
<noscript>
<a href="#"><img alt="Analytics, Inc. "
src="http://tableau.russellchristopher.org:81/Background.gif"
style="border: none" /></a>
</noscript>
<object class="tableauViz" width="654" height="1469" style="display:none;">
<param name="host_url" value="http%3A%2F%2Fpublic.tableausoftware.com%2F"
/>
<param name="site_root" value="" />
<param name="name" value="AnalyticsIncJavaScript/AnalyticsInc" />
<param name="tabs" value="no" />
<param name="toolbar" value="yes" />
<param name="static_image" value="tableau.russellchristopher.org:81/Background.gif"
/>
<param name="animate_transition" value="yes" />
<param name="display_static_image" value="yes" />
<param name="display_spinner" value="" id="display_spinner" />
<param name="display_overlay" value="yes" />
<param name="display_count" value="yes" />
</object>
</div>
Here’s what I’ve come up with (JSFiddle here: http://jsfiddle.net/9vBGq/ )
$(document).ready(function () {
var $placeholder = $('<div class="tableauPlaceholder" style="width:654px; height:1469px;background-image: url("http%3A%2F%2Ftableau.russellchristopher.org:81%2FBackground.gif"); top: 0px; left: 0px; width: 100%; margin-left: 76px;"></div>'),
$noscript = $('<noscript> <a href="#"><img alt="Analytics, Inc. " src="http%3A%2F%2Ftableau.russellchristopher.org:81/Background.gif" style="border: none" /></a></noscript>'),
$tableauViz = $('<object class="tableauViz" width="654" height="1469"></object>'),
$host_url = $('<param name="host_url" value="http%3A%2F%2Fpublic.tableausoftware.com%2F">'),
$site_root = $('<param name="site_root" value="" />'),
$sheetName = $('<param name="name" value="AnalyticsIncJavaScript/AnalyticsInc" />'),
$tabs = $('<param name="tabs" value="no" />'),
$toolbar = $('<param name="toolbar" value="yes" />'),
$static_image = $('<param name="static_image" value="http://tableau.russellchristopher.org:81/Background.gif"/>'),
$animate_trasnsition = $('<param name="animate_transition" value="yes" />'),
$display_static_image = $('<param name="display_static_image" value="yes" />'),
$display_overlay = $('<param name="display_overlay" value="yes" />'),
$display_count = $('<param name="display_count" value="yes" />'),
$display_spinner = $('<param name="display_spinner" value="' + 'no' + '" />');
$placeholder.append($noscript).append($tableauViz).append($host_url).append($site_root).append($sheetName).append($tabs).append($toolbar).append($static_image).append($animate_trasnsition).append($display_static_image).append($display_overlay).append($display_count).append($display_spinner).appendTo('body');
console.log(document.body);
});
From what I can see in my console.log, there are multiple problems – and I’m still too new to this stuff to know exactly why:

- The URL Encoding in my
<div>looks munged. What did I do wrong? - The
<a>tag nested inside the noscript block looks bad - There is a closing
</object>tag when it should close after I list my params - Closing
/>on each my my params is missing- again URL encoding
strangeness, I assume but not sure how to handle.
I suspect you pros and kick me in the right direction in a couple of seconds….please kick me as you see fit? Thanks.
I think the best solution would be to create a template in your html and read that instead of making it in javascript..
Something like
then you need this code to load the template and change the placeholder
Demo at http://jsfiddle.net/gaby/9vBGq/1/
(I have removed the
noscriptelement from the template since everything is done through script)