Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Problem adding javascript to category description

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 08-23-2010, 08:13 AM
 
RStoelting RStoelting is offline
 

Advanced Member
  
Join Date: Jun 2007
Posts: 49
 

Default Problem adding javascript to category description

I want to add a link to a category description that will open a new window with a specific size and at the top right of the users screen. Here is the script:

Code:
<script type="text/javascript"> <!-- function popup(url) { params = 'top=0, left=0'; params += ', resizable=yes'; params += ', width=620'; params += ', height=600'; params += ', scrollbars=1'; params += ', toolbar=yes, menubar=yes'; newwin=window.open(url,'windowname4', params); if (window.focus) {newwin.focus()} return false; } // --> </script>
But when I add this code to the description field for "Modify Category" and save, the entire content of the description field is deleted.

Here is the code that applies the javascript to the link:
Code:
<a href="javascript: void(0)" onclick="popup('URL')">Click here</a>
Before adding the javascript code above, I was able to add this link to the category without losing the description. But of course, without the javascript code, the link did not function.

How can I add this javascript to a category?
__________________
Version 4.6.1 Gold [unix]
Reply With Quote
  #2  
Old 08-23-2010, 10:15 AM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Problem adding javascript to category description

The easiest thing to do is to add it to skin1/common.js - then it will be available to any page that calls common.js - which I think may be every page on 4.1.x (if you do this, remove the <script> and </script>)

If you only want to call it on the category pages - you can add it to skin/1/customer/home.tpl with an if/than statement to only use it when you want it. If you add it to a template, be sure to surround it with {literal} and {/literal} tags.
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote

The following user thanks gb2world for this useful post:
MrSoft (10-13-2010)
  #3  
Old 08-24-2010, 11:54 AM
 
RStoelting RStoelting is offline
 

Advanced Member
  
Join Date: Jun 2007
Posts: 49
 

Default Re: Problem adding javascript to category description

Adding the javascript to common.js worked perfectly

Thanks for the help.
__________________
Version 4.6.1 Gold [unix]
Reply With Quote
  #4  
Old 02-24-2012, 04:35 PM
 
spiredem spiredem is offline
 

Advanced Member
  
Join Date: Oct 2008
Posts: 87
 

Default Re: Problem adding javascript to category description

Quote:
Originally Posted by RStoelting
Adding the javascript to common.js worked perfectly

Thanks for the help.

I have the same issue and wan to apply this fix. What exactly am I adding to common.js? The whole code that I'm trying to use on the page?
__________________
X-Cart Gold 4.1.10
Add-on: X-AOM (Advanced Order Management)
Reply With Quote
  #5  
Old 02-24-2012, 04:39 PM
 
spiredem spiredem is offline
 

Advanced Member
  
Join Date: Oct 2008
Posts: 87
 

Default Re: Problem adding javascript to category description

This is my code for having an image with a mouseover area (map). Which part do I add to common.js?

Quote:
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
<body onLoad="MM_preloadImages('http://www.url.com/images/C/lina-cat-hero.jpg')"><img src="http://www.url.com/images/C/lina-cat.jpg" width="600" height="420" border="0" usemap="#Map" id="Image1">
<map name="Map">
<area shape="rect" coords="9,351,215,391" href="#" onMouseOver="MM_swapImage('Image1','','http://www.url.com/images/C/lina-cat-hero.jpg',1)" onMouseOut="MM_swapImgRestore()">
</map>
__________________
X-Cart Gold 4.1.10
Add-on: X-AOM (Advanced Order Management)
Reply With Quote
  #6  
Old 02-24-2012, 05:10 PM
 
spiredem spiredem is offline
 

Advanced Member
  
Join Date: Oct 2008
Posts: 87
 

Default Re: Problem adding javascript to category description

ah! think i got it. thanks guys!
__________________
X-Cart Gold 4.1.10
Add-on: X-AOM (Advanced Order Management)
Reply With Quote
  #7  
Old 02-25-2012, 04:48 PM
 
spiredem spiredem is offline
 

Advanced Member
  
Join Date: Oct 2008
Posts: 87
 

Default Re: Problem adding javascript to category description

Ok so this isn't working on this part. I put the following into skin1/common.js
Quote:
/*
This JavaScript does the work when mouse-sensitive areas are triggered.
*/
function HideDIV(d) {
document.getElementById(d).style.display = "none"; }
function DisplayDIV(d) {
document.getElementById(d).style.display = "block"; }

and here's how I call it on the page
Quote:
<span class="heroes" onmouseover="HideDIV('desc2');DisplayDIV('desc1')" )" >
brand bio
</span>
__________________
X-Cart Gold 4.1.10
Add-on: X-AOM (Advanced Order Management)
Reply With Quote
  #8  
Old 02-26-2012, 08:03 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Problem adding javascript to category description

When the page is loaded in the browser, is everything intact? What I mean, is all the code reaching the browser? Can you inspect element and see all your code?
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #9  
Old 02-26-2012, 08:55 AM
 
spiredem spiredem is offline
 

Advanced Member
  
Join Date: Oct 2008
Posts: 87
 

Default Re: Problem adding javascript to category description

Yes all the code is intact on the live end. The action works when the script is on the page (offsite) but when it's only in common.js, it doesn't seem to do anything.
It worked with mouseover swap images but it's not working with swap divs.
__________________
X-Cart Gold 4.1.10
Add-on: X-AOM (Advanced Order Management)
Reply With Quote
  #10  
Old 02-26-2012, 09:16 AM
 
spiredem spiredem is offline
 

Advanced Member
  
Join Date: Oct 2008
Posts: 87
 

Default Re: Problem adding javascript to category description

Oh this is embarrassing - I was uploading the unchanged version of common.js. Works now!
__________________
X-Cart Gold 4.1.10
Add-on: X-AOM (Advanced Order Management)
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:24 AM.

   

 
X-Cart forums © 2001-2020