Page 1 of 1

Javascript and the {literal} {/literal} tags [SOLVED]

Posted: Tue Apr 22, 2008 3:57 pm
by masada
hi,

In my footer I have a table with 2 cells in it. The left cell has a simple image in it. In the right cell I want to have random images show whenever a new page loads, refreshing, etc. (advertisements). Here is my code for that:

Code: Select all

<__script__ language="JavaScript">
<!--

function random_imglink(){
  var myimages=new Array()
  //specify random images below. 
  myimages[1]="http://www.ises-msp.org/newsite2/uploads/images/ads/coppersmith.jpg"
  myimages[2]="http://www.ises-msp.org/newsite2/uploads/images/ads/ises.jpg"
  myimages[3]="http://www.ises-msp.org/newsite2/uploads/images/ads/meetingPages.jpg"

  //specify corresponding links below
  var imagelinks=new Array()
  imagelinks[1]="http://www.wsabstract.com"
  imagelinks[2]="http://www.dynamicdrive.com"
  imagelinks[3]="http://www.java-scripts.net"

  var ry=Math.floor(Math.random()*myimages.length)

  if (ry==0)
     ry=1
     document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}

  random_imglink()
//-->
</__script>
I've tested this code on it's own (Dreamweaver) and it works fine.

My problem is where (and how) to put this code. I've tried putting it in the HTML dialog box for the footer page (in it's respective table cell) but it doesn't work. It keeps turning the code into a single line which, shouldn't matter, but I'm not sure. I've also tried with and without the {literal} {/literal} tags to no avail. I've read in previous forums that it may go in the footer template but if that's true how would I tell it to show in the assigned cell I need it to be in? I'm very confused of all this.

Re: Javascript and the {literal} {/literal} tags

Posted: Tue Apr 22, 2008 4:02 pm
by calguy1000
1) put all of your javascript, wrapped in {literal} and {literal} tags, into a global content block
2) Call the global content block from the desired table cell (ugh) with {global_content name='blah'}

Re: Javascript and the {literal} {/literal} tags

Posted: Tue Apr 22, 2008 4:17 pm
by masada
Where am I calling the global content block from, the footer content block or the whole template? I think my problem is that I'm making changes from the footer content block (with the wysiwyg editor). Is that correct?

Re: Javascript and the {literal} {/literal} tags

Posted: Tue Apr 22, 2008 4:23 pm
by Nullig
Try adding the tag without the WYSIWYG editor.

Nullig

Re: Javascript and the {literal} {/literal} tags

Posted: Tue Apr 22, 2008 4:33 pm
by masada
I think I'm doing this wrong to begin with.
I created a global content block called "footer." I made a 2-cell table for a static image on one side and on the other ads to load randomly. With calguy1000's advice, I created a new global content block called "adsjs" and then placed the {global_content name='adsjs'} in the empty table cell. Doing it this way doesn't parse the javascript, it just displays the code in that cell. Even whilst using the {literal} {/literal} tags. Was this how it was to be done?

Re: Javascript and the {literal} {/literal} tags

Posted: Tue Apr 22, 2008 5:16 pm
by masada
In other words, the javascript should show in a global content that was already created (which has a table cell for it).

Re: Javascript and the {literal} {/literal} tags [SOLVED]

Posted: Tue Apr 22, 2008 5:39 pm
by masada
ok, it's working.

I did not create a new global content block. Instead, I just inserted the javascript to the cell that I wanted the ads to rotate in with the {literal} {/literal} tags. I swore I did that before but it just didn't go for some reason. It may be the javascript headers. See below for example of correct format when adding javascript to a page (place this where ever you want the images to appear):

Code: Select all


{literal}
<__script__ language="JavaScript">
<!--

function random_imglink(){
  var myimages=new Array()
  //specify random images. (no limit): 
  myimages[1]="uploads/images/image1.jpg"
  myimages[2]="uploads/images/image2.jpg"
  myimages[3]="uploads/images/image3.jpg"

  //now specify corresponding links for images:
  var imagelinks=new Array()
  imagelinks[1]="http://www.webAddress1.com"
  imagelinks[2]="http://www.webAddress2.com"
  imagelinks[3]="http://www.webAddress3.net"

  var ry=Math.floor(Math.random()*myimages.length)

  if (ry==0)
     ry=1
     document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}

  random_imglink()
//-->
</__script>
{/literal}
This should do it. Thanks to Calguy1000 and Nullig for the help! :)

Cheers

Re: Javascript and the {literal} {/literal} tags [SOLVED]

Posted: Sun May 24, 2009 9:20 pm
by barbet
what did you do in the header, since I have the same problem. Can't get a javascript code working even with tags.

Re: Javascript and the {literal} {/literal} tags [SOLVED]

Posted: Sun May 24, 2009 10:22 pm
by Peciura
I use a bit different header:

Code: Select all

{literal}
<__script__ type="text/javascript">
...
</__script>
{/literal}
And the code looks the same whether you put it to GCB or to content, or to template.

Re: Javascript and the {literal} {/literal} tags [SOLVED]

Posted: Tue Aug 04, 2009 12:30 pm
by dmaireroa
Nice! I was looking around how to add javascript and got it going.

CHEERS :)

Re: Javascript and the {literal} {/literal} tags [SOLVED]

Posted: Fri Oct 23, 2009 8:59 am
by denli
Hello!

I got the Analytics code working but the google ads code is another problem.

In my google account the conversions are not counted.

I placed this conversion code also in {literal} code and placed it in a special made thank you template which is used by a thank you page. These are shown after a successful form submission.

I clicked on a google ad of us and then went to the form filled it in got the thank you al is ok in the source an I even see the link google telling te visitor google is monitoring the page.

But in my account no clicks where counted?

Could this be a cmsms problem or is this a google thing?