X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Problem adding javascript to category description (https://forum.x-cart.com/showthread.php?t=55211)

RStoelting 08-23-2010 08:13 AM

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?

gb2world 08-23-2010 10:15 AM

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.

RStoelting 08-24-2010 11:54 AM

Re: Problem adding javascript to category description
 
Adding the javascript to common.js worked perfectly:D

Thanks for the help.

spiredem 02-24-2012 04:35 PM

Re: Problem adding javascript to category description
 
Quote:

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

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?

spiredem 02-24-2012 04:39 PM

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>


spiredem 02-24-2012 05:10 PM

Re: Problem adding javascript to category description
 
ah! think i got it. thanks guys!

spiredem 02-25-2012 04:48 PM

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>


totaltec 02-26-2012 08:03 AM

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?

spiredem 02-26-2012 08:55 AM

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.

spiredem 02-26-2012 09:16 AM

Re: Problem adding javascript to category description
 
Oh this is embarrassing - I was uploading the unchanged version of common.js. Works now!


All times are GMT -8. The time now is 01:37 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.