Wednesday, November 9, 2011

How to import javascript in Google Site

*** Newest Update ***
A Bad News for the Gadgets method is no longer available at 14 November 2011, I don’t what’s happen. I guess the compatible issue comes from some update of Google or Gamestar Mechanic. The only thing I can go is suggest you to use an image with hyperlink for showing the game.
For example:
<a href="http://gamestarmechanic.com/game/shared/18756/85d77600b08b4f795b5528ae51ae454f">
<img src="YourGameImage.jpg" border="0" height="640" width="540" alt="Game1" />
</a>

I found that Google Site does not support javascript which means you cannot directly add you Gamestar Mechanic’s hyperlink to Google Site even using <iframe> tag. If you use <iframe> tag, it only can be showed on Firefox but not IE. I found a method for you to achieve this work!

Step 1. Go to Gamestar Mechanic get your game embed
Our embed is:
<div id="gsm_17601"><script type="text/javascript">var _gsm = _gsm || []; _gsm.push(['_node_id', 'gsm_17601']); _gsm.push(['_game_id', '17601']); _gsm.push(['_dynamic_url', 'gamestarmechanic.com/xml/get/']); _gsm.push(['_base_url', 'gamestarmechanic.com']); _gsm.push(['_info_url', 's3.amazonaws.com/gsm-beta-images/embed_info_game_373158.txt?AWSAccessKeyId=AKIAI7PSLPMJVIRA2JTQ&Expires=1636085939&Signature=ZN3%2BjDndvKvWS6VnUKXJPA1kwoI%3D']);(function(){var embedUrl_http = 'http://gamestarmechanic.com/embed/embed_game_fast.js'; var embedUrl_https = 'https://gamestarmechanic.com/embed/embed_game_fast.js'; var embedUrl = ('https:' == document.location.protocol ? embedUrl_https : embedUrl_http); var gsm = document.createElement('script'); gsm.type = 'text/javascript'; gsm.src = embedUrl; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gsm, s);})(); </script></div>


Step 2. Open a “Notpad” from your windows
Start > Run > type ‘notepad’ > Press Enter.

Step 3. Copy this script to the notepad
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="" />
<Content type="html">
<![CDATA[

]]>
</Content>
</Module>

Step 4. Add your embed to the script between<![CDATA[and]]>
It will look like:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="" />
<Content type="html">
<![CDATA[

<div id="gsm_17601"><script type="text/javascript">var _gsm = _gsm || []; _gsm.push(['_node_id', 'gsm_17601']); _gsm.push(['_game_id', '17601']); _gsm.push(['_dynamic_url', 'gamestarmechanic.com/xml/get/']); _gsm.push(['_base_url', 'gamestarmechanic.com']); _gsm.push(['_info_url', 's3.amazonaws.com/gsm-beta-images/embed_info_game_373158.txt?AWSAccessKeyId=AKIAI7PSLPMJVIRA2JTQ&Expires=1636085939&Signature=ZN3%2BjDndvKvWS6VnUKXJPA1kwoI%3D']);(function(){var embedUrl_http = 'http://gamestarmechanic.com/embed/embed_game_fast.js'; var embedUrl_https = 'https://gamestarmechanic.com/embed/embed_game_fast.js'; var embedUrl = ('https:' == document.location.protocol ? embedUrl_https : embedUrl_http); var gsm = document.createElement('script'); gsm.type = 'text/javascript'; gsm.src = embedUrl; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gsm, s);})(); </script></div>


]]>
</Content>
</Module>

Step 5. Click File > Save > Change the save type toAll File’ > name itgame1.xmlthen you will see a xml file will created.

Step 6. Back to your Google Site (I suppose you have login) > ClickMorebutton > Manage Site > Attachments > Upload > upload your 'game1.xml'

Step 7
. Try your link whether work or not
https://sites.google.com/site/YourWebsiteName/game1.xml

My link is: https://sites.google.com/site/bloggingtips2011/game2.xml

Step 8. Back to your editing page > insert > more gadgets > add gadgets by url > paste your .xml link

Set width to 640 pixels
Set height to 540 pixels
OK !! Done

Learn from: http://code.google.com/apis/gadgets/docs/gs.html

4 comments:

  1. Thanks a lot for sharing this workaround - it's a bit odd that these embeds sometimes don't work in Google Sites - why do you think it doesn't support javascript?

    ReplyDelete
  2. To Christoph,
    I think it come from the HTML complier problem. Google Site's HTML complier cannot classify the contents whether correct or not when typing the code within <script> tag, even http://validator.w3.org/ also has similar problem for checking javascript. Therefore, when we directly type javascript with using <script>, the Google Site editor will pop up an alert which said ‘HTML content will be modified WARNING: Your HTML contains some tags that are not permitted. These have been removed from your changes’. However, Google Site allows end user to use javascript via gadgets, that why I share this method with using XML file.

    ReplyDelete
  3. Ivan this is so impressive!!!!!
    =)

    ReplyDelete