Problem with window.location.replace() with IE7/8 and SVG

Discuss SVG code, accessible via the XML Editor.
nguyenluthuy
Posts: 2
Joined: Fri Aug 05, 2011 2:43 pm

Problem with window.location.replace() with IE7/8 and SVG

Postby nguyenluthuy » Fri Aug 05, 2011 2:48 pm

I had a problem using window.location.replace(url) with IE7/8 while writing a javascript function in an SVG file. This worked correctly with IE6 however this function did nothing with IE7/8, no script error popup appeared.

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.

User avatar
BobSongs
Posts: 324
Joined: Fri Sep 14, 2007 2:18 pm
Location: Montreal, Canada

Re: Problem with window.location.replace() with IE7/8 and SV

Postby BobSongs » Sat Aug 06, 2011 5:43 pm

It would appear the problem isn't with SVG or with the SVG you provided. Internet Explorer has always been a bit of a rogue. Now that other browsers are complying with the W3C's standards... even the big software giant sees the need to do so.

It's good to hear MSFT's latest browser has better compliance with the W3C's standards. It's not surprising to hear their two previous releases flouted them. But that's the problem of having this rogue browser surf the web: we're left with creating pages for it... and then for everyone else.

To answer your question though: you'd have to do some research into Internet Explorer 7 and 8 to find out how to work around this issue. Clearly the flaw lies with the browser versions and not SVG.

nguyenluthuy
Posts: 2
Joined: Fri Aug 05, 2011 2:43 pm

Re: Problem with window.location.replace() with IE7/8 and SV

Postby nguyenluthuy » Fri Aug 12, 2011 2:32 pm

Thanks for your feedback. I tried to research a lot but I could not find out any ways to overcome this problem. It seems that the location object has the read-only property when viewing SVGs in IE7/8. I worked around by adding some scripts in SVG to call a function in parent html which then calls location.replace().


Return to “SVG / XML Code”