I added this to my WordPress page
if (script.readyState && script.onload!==null){
script.onreadystatechange= function () {
if (this.ready
Another option is to make a shortcode. In this example, the shortcode will only be printed if it contains the attributes x and y, e.g.: [myscript x="10" y="20"]. I'm using a simple script that shows a JS alert dialog with the attributes values.
add_shortcode( 'myscript', 'sample_shortcode_so_6195635' );
function sample_shortcode_so_6195635( $atts, $content = null )
{
if( isset( $atts['x'] ) && isset( $atts['y'] ) )
{
$x = $atts['x'];
$y = $atts['y'];
// See: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
$html = <<Show Shortcode Atts
HTML;
return $html;
}
}