Q:

How to see UTF-8 character as a SVG parameter correctly?

I have SVG file with text that I want to set it by parameter. My HTML like this:
<object type="image/svg+xml" data="../src/img/road-map-header.svg?code=سلام"></object>

and my svg file like this:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1134.6 70.64" direction="rtl" xml:lang="ar">   
<title>Asset 2</title>
<g id="Layer_2" data-name="Layer 2">
    <g id="Layer_1-2" data-name="Layer 1">
        <text class="cls-1" transform="translate(913.98 39.02)" id="level-one">
            --parameter insert here--
        </text>
    </g>           
</g>
<script type="application/ecmascript"> <![CDATA[
        // when used as an object, we'll allow attributes to be changed by params passed in the query string
        var paramList = ['code'];
        var refs = [];
        var href = document.defaultView.location.href;
        if ( -1 != href.indexOf("?") ) {
            var paramList = href.split("?")[1].split(/&|;/);
            for ( var p = 0, pLen = paramList.length; pLen > p; p++ ) {
                var eachParam = paramList[ p ];
                var valList = eachParam.split("=");
                var name = unescape(valList[0]);
                var value = unescape(valList[1]);
                refs[name] = value;
            }
    }
    // do stuff with the params
    if(refs['code'] != undefined){
        document.getElementById("level-one").innerHTML = refs['code'];        
    }else{
        document.getElementById("errorcode").innerHTML = '!';
    }
    ]]>
</script>

When I set English character parameter as code every things is okay, but when I set Arabic character show me Ø³ÙØ§Ù.How to show svg unicode parameter correctly?

A:

Please replace your SCRIPT tag with the following:
<script type="application/ecmascript"> <![CDATA[
function getParameterByName(name, url) {
    // Thanks to https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript 
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

var href = document.defaultView.location.href;
var code = getParameterByName('code', href);

if (code != undefined){
  document.getElementById("level-one").textContent = code;
} else {
  document.getElementById("errorcode").textContent = '!';
}
]]>
</script>

I must admit to not being a big fan of SCRIPT tags in SVG so would have handled it differently myself, but I've found the above works with Arabic and Mandarin:
<object type="image/svg+xml" data="mysvg.svg?code=سلام"></object>

<object type="image/svg+xml" data="mysvg.svg?code=普通话"></object>

