Search code examples
javascriptjquerygoogle-sitessites

Putting hyperlinks on Google sites using jQuery


I am trying to put a text (containing a hyperlink) using the click function in jQuery.

var publicationsText = "Rohit. <a href=\"http://www.google.com\" onmouseover=\"this.style.color=#EC4D48;\" onmouseout=\"this.style.color=#666;\" style=\"color:#666;\">Emerging Energy</a>";

    $('#publicationsID').click(function(){ 
      $("#homepage").html(publicationsText);
      return false;
    });

This works fine as intended on my local box. But when I publish this on Google sites, the HTML produced is:

<div id="container-caja-guest-0___">
<div id="homepage-caja-guest-0___">
Rohit.<a target="_blank" style="color: #666">Emerging Energy</a>
</div>
</div>

And the hyperlink is automatically removed.

Can any one please suggest a workaround that works on the Google sites?

Moreover the site is available at: http://www.wattalyst.org (and you can see the problem in Contact/Publications page)

Thanks!


Solution

  • Your string is incorrectly formatted. You need to escape the quotes and merge the lines

    var publicationsText = "Rohit. <a href=\"http://www.google.com\" "+
        " onmouseover=\"this.style.color=#EC4D48;\" onmouseout=\"this.style.color=#666;\" "+ 
        " style=\"color:#666;\">Emerging Energy</a>";