Hi,
I am trying to add current time to the svg file I have using Ecmascript.
following is the code I have. Unfortunately its not working . can someone help me fix it?
Thank you
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300">
<text x="0" y="15" fill="red">It is now
<script type="text/javascript">
<![CDATA[
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(month + "/" + day + "/" + year);
]]>
</script>
</text>
</svg>
Current time/date in SVG
Re: Current time/date in SVG
Maybe something like this.
<text id="datetime" x="0" y="15" fill="red"></text>
<script type="text/javascript">
<![CDATA[
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var text = "It is now " + (month + "/" + day + "/" + year;
var textNode = document.createTextNode(text);
document.getElementById("datetime").appendChild(textNode);
]]>
</script>
<text id="datetime" x="0" y="15" fill="red"></text>
<script type="text/javascript">
<![CDATA[
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var text = "It is now " + (month + "/" + day + "/" + year;
var textNode = document.createTextNode(text);
document.getElementById("datetime").appendChild(textNode);
]]>
</script>
Re: Current time/date in SVG
v1nce wrote:Maybe something like this.
<text id="datetime" x="0" y="15" fill="red"></text>
<script type="text/javascript">
<![CDATA[
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var text = "It is now " + (month + "/" + day + "/" + year;
var textNode = document.createTextNode(text);
document.getElementById("datetime").appendChild(textNode);
]]>
</script>
Hi,
thank you for y9our reply.
I tried :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300">
<text id="datetime" x="0" y="15" fill="red"></text>
<script type="text/javascript">
<![CDATA[
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var text = "It is now " + (month + "/" + day + "/" + year;
var textNode = document.createTextNode(text);
document.getElementById("datetime").appendChild(textNode);
]]>
</script>
</svg>
but it is not still working. any other suggestion?
Re: Current time/date in SVG
tested in firefox
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg onload="init(evt)" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1000" height="1000" id="svg2" version="1.1"
inkscape:version="0.48.1 r9760"
sodipodi:docname="star.svg">
<script type="text/ecmascript"><![CDATA[
function init(evt) {
if ( window.svgDocument == null )
svgDocument = evt.target.ownerDocument;
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var text = "It is now " + month + "/" + day + "/" + year;
var textNode = evt.target.ownerDocument.createTextNode(text);
evt.target.ownerDocument.getElementById("datetime").appendChild(textNode);
}
]]></script>
<g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1">
<text id="datetime" x="0" y="15" fill="red"></text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg onload="init(evt)" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1000" height="1000" id="svg2" version="1.1"
inkscape:version="0.48.1 r9760"
sodipodi:docname="star.svg">
<script type="text/ecmascript"><![CDATA[
function init(evt) {
if ( window.svgDocument == null )
svgDocument = evt.target.ownerDocument;
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var text = "It is now " + month + "/" + day + "/" + year;
var textNode = evt.target.ownerDocument.createTextNode(text);
evt.target.ownerDocument.getElementById("datetime").appendChild(textNode);
}
]]></script>
<g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1">
<text id="datetime" x="0" y="15" fill="red"></text>
</g>
</svg>