I can use window.self.navigate(url), however this will create a new entry in browser's history so I need to use window.location.replace. My code is now working with IE6, IE9, FF4 and Chrome 12 but it doesn't work with IE7/8.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<svg width="5cm" height="3cm" viewBox="0 0 5 3" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<desc>
Example link01 - a link on an ellipse
</desc>
<rect x=".01" y=".01" width="4.98" height="2.98"
fill="none" stroke="blue" stroke-width=".03"/>
<a xlink:href="http://google.com.vn" onclick="testJavascript('test')" id="test">
<ellipse cx="2.5" cy="1.5" rx="2" ry="1"
fill="red" />
</a>
<script type='text/ecmascript'>
<![CDATA[
function testJavascript(elementId){
var currentElement = document.getElementById(elementId);
var targetLocation = currentElement.getAttribute('xlink:href');
if(typeof(parent.window) != 'undefined')
{
parent.window.location.replace(targetLocation);
currentElement.removeAttribute('xlink:href');
}
else
{
location.replace(targetLocation);
}
}
]]>
</script>
</svg>
Please let me know if I did something wrong. Thanks.