Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I need to use a JavaScript patch in my Google Sites, but the problem is I don't understand how to place them and use it as Google Gadget.

<!DOCTYPE <strong class="highlight">html</strong> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<<strong class="highlight">html</strong> xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
var timerid = 0;
var <strong class="highlight">images</strong> = new Array(  "image1.jpg",
            "image2.jpg",
            "image3.jpg");
var countimages = 0;
function startTime()
{
    if(timerid)
    {
        timerid = 0;
    }
    var tDate = new Date();

    if(countimages == <strong class="highlight">images</strong>.length)
    {
        countimages = 0;
    }
    if(tDate.getSeconds() % 5 == 0)
    {
        document.getElementById("img1").src = <strong class="highlight">images</strong>[countimages];
    }
    countimages++;

    timerid = setTimeout("startTime()", 1000);
}
</script>
</head>

<body onload="startTime();">
<img id="img1" src="image3.jpg" />
</body>
</html>

I'm hoping for specific instructions using the JavaScript code I provided since I've found general Google Sites embedding instructions unfathomable. However with specific instructions I will be able to figure out how to use scripts in Google Sites in the future as well.

share|improve this question
add comment

3 Answers 3

You cannot add JavaScript directly to your Google Sites page. You can, however add a Google Gadget that has JavaScript in it. You can try the Google Gadget Builder. You may not get the result that you want, however, since your JavaScript is not valid. For example, your statements with (x)html elements will cause the JS engine to error.

var <strong class="highlight">images</strong> = new Array(  "image1.jpg",
        "image2.jpg",
        "image3.jpg");

It may work with E4X, but Google Sites is not rendered as XML. (Yes, it does have the XML doctype, but not the header, so it will not render as XML)

In addition to Google Gadgets, you can also try Google Apps Scripts. It allows for some server side automation.

share|improve this answer
add comment

I am not sure what you are trying to do with your script, but have you looked too see if you can accomplish what you want with a Google Apps Script? It looks like using Google App Scripts within Google Sites is pretty easy. Here is a tutorial - Getting Started with Apps Script and Google Sites.

share|improve this answer
add comment

You can also use CodeWrapper. It's a gadget that allows you to paste your javascript into it and run it as a google gadget, basically allowing you to enter the javascript into the html without it being blocked. Go to Insert > more gadgets > search for codewrapper.

It should solve your problem. It's solved a few of mine already.

share|improve this answer
1  
How do you use it? –  Oxwivi Sep 23 '11 at 11:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.