Passed URL string not interpret as a string

I read quite some articles and tried some approaches, but couldn't get it to work.

htmlCode += '<button id="' + addButtonId + '" title="' + addButtonTitle + '" class="button" onclick="getProductUrl(' + url + '); return false;"><span><span>' + addWithButonTitle + '</span></span></button>';

and the function itself:

getProductUrl: function(url) {
        return setLocation('\'' + decodeURIComponent(url) + document.getElementById('qty_field').value + '\'');

Apparently, the string value of the url is not treated as a string. I get an error of missing bracket here: getProductUrl(http:^// of the url. Of course the problem is not in the bracket, but in the fact that the // are treated as a start of a comment.

So the thing that I have to do is to pass this url string value CORRECTLY as a string. I tried first decoding and then passing (because decodeURIComponent(url) should return string. Also I tried String(url) and url + "". Also somehow escaping the special characters: url.replace('/','\/') or even the /g thingy, which didn't work at all.

So, all these approaches were unsuccessful. I would really appreciate a hint or a solution here.


Try this one

onclick="getProductUrl('" + url + "');"

For your updated line of code:

htmlCode += '<button id="' + addButtonId + '" title="' + addButtonTitle + '" class="button" onclick="getProductUrl(\'' + url + '\'); return false;"><span><span>' + addWithButonTitle + '</span></span></button>';

Need Your Help

Timer on Excel VBA

excel vba excel-vba

Dim StartTime As Date

I want to put db tables in same database. How?

ios database join sqlite

My iOS program download [A.sqlite3] file in server.