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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
masada
Forum Members
Forum Members
Posts: 29
Joined: Thu Nov 08, 2007 6:04 pm

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

Post 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.
Last edited by masada on Tue Apr 22, 2008 5:40 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post 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'}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
masada
Forum Members
Forum Members
Posts: 29
Joined: Thu Nov 08, 2007 6:04 pm

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

Post 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?
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

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

Post by Nullig »

Try adding the tag without the WYSIWYG editor.

Nullig
masada
Forum Members
Forum Members
Posts: 29
Joined: Thu Nov 08, 2007 6:04 pm

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

Post 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?
masada
Forum Members
Forum Members
Posts: 29
Joined: Thu Nov 08, 2007 6:04 pm

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

Post by masada »

In other words, the javascript should show in a global content that was already created (which has a table cell for it).
masada
Forum Members
Forum Members
Posts: 29
Joined: Thu Nov 08, 2007 6:04 pm

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

Post 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
barbet
Forum Members
Forum Members
Posts: 10
Joined: Sun May 24, 2009 5:06 pm

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

Post 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.
Peciura

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

Post 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.
Last edited by Peciura on Sun May 24, 2009 10:25 pm, edited 1 time in total.
dmaireroa
Forum Members
Forum Members
Posts: 110
Joined: Wed Jul 15, 2009 12:35 am

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

Post by dmaireroa »

Nice! I was looking around how to add javascript and got it going.

CHEERS :)
denli
Forum Members
Forum Members
Posts: 86
Joined: Tue Sep 04, 2007 12:26 pm

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

Post 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?
Post Reply

Return to “CMSMS Core”