0

i want to do this:

<object type="image/svg+xml" id="tornado5" data="bitmaps/tornado2.svg">
</object>

but i want to do it in javascript dynamically... i tried:

var object2 = document.createElement("object");
object2.type = "image/svg+xml";
object2.data = 'bitmaps/tornado2.svg';
object2.id = "tornado5";
document.getElementById('objLayer').appendChild(object2);  // no .onload method

var ele=document.getElementById("tornado5");
var links = ele.contentDocument.getElementsByClassName('myClass'); //paths in file use
for (var i=0;i<links.length;i++){ links[i].style.fill="#00ff00"; } 

the top html way can call the 3-line-js-color-mod at bottom and it will mod the color of the svg. But if i load the svg the js way, the svg loads, but the color mod wont work. (you can't mod the contentDocument thru an img, only thru an object i'm told).

question 11374059 asks a similar question and he was told to use img. No good here.


Check your server logs and see if there is an error related to the require_once('config.php') in Google_Client.php (If the file wasn't found, the script should have stopped).

When you do your require_once('Google_Client.php'), the following code is executed from that file. After you do your require, $apiConfig should be visible to your script.

// hack around with the include paths a bit so the library 'just works'
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());

require_once "config.php";
// If a local configuration file is found, merge it's values with the default configuration
if (file_exists(dirname(__FILE__)  . '/local_config.php')) {
  $defaultConfig = $apiConfig;
  require_once (dirname(__FILE__)  . '/local_config.php');
  $apiConfig = array_merge($defaultConfig, $apiConfig);
}

Note that you do not touch config.php. If you need to override anything in there, you create local_config.php.

From my system with PHP 5.3 I used this script. The script as show below throws no errors. Unsetting the $apiConfig replicates your error.

<?php

require_once('src/Google_Client.php');

print_r($apiConfig);
// uncommenting the next line replicates issue.
//unset($apiConfig);
$api = new Google_Client();

?>
4

1 回答 1

1

我建议使用 Object.setAttribute(attr, val); 在对象标签上。IE:

var object2 = document.createElement("object");
object2.setAttribute("type", "image/svg+xml");
于 2013-01-25T02:30:25.800 回答