There is one line in this code that is troubling me. I am using Google search API, but my question is not related to Google API, it is JavaScript.
In the code below (complete code is at the bottom):
thisResult.url holds the value for the url, the href works correctly and link is fine, but the onclick event handler, where I show an alert containing the value of the thisResult.url does not work (the alert does not popup).
However, if I change the alert to somethign like this: alert('test code'), then it works. Any suggestions? Thanks in advance.
Complete code:Code:results += "<a href=\"" + thisResult.url + "\" target=\"_blank\" onclick=alert("+thisResult.url+")>" + thisResult.title + "<\/a><br \/>";
Code:for (var i = 0; i < gWebSearch.results.length; i++) { var thisResult = gWebSearch.results[i]; results += "<p>"; //results += "<a href=\"" + thisResult.url + "\">" + thisResult.title + "<\/a><br \/>"; results += "<a href=\"" + thisResult.url + "\" target=\"_blank\" onclick=alert("+thisResult.url+")>" + thisResult.title + "<\/a><br \/>"; results += thisResult.content + "<br \/>"; results += "<span class=\"url\">" + thisResult.url + "<\/span>"; if (thisResult.cacheUrl) { results += " - <a class=\"cached\" href=\"" + thisResult.cacheUrl + "\">Cached <\/a>"; } results += "<\/p>"; }




Bookmarks