RSS Feed

Archive for the ‘Javascript’ Category

Open Popup Window On Tabbed Browser – Firefox, Chrome and IE

April 19, 2011 by admin No Comments »

If you are a developer and want a way to ensure your clients/site users have the same window popup experience regardless on whether browser tabs are on or not, here is a snipt Javascript function that can help you achieve just that.

 function PopupWinF(Url, name, width, height, features) {
        var w	
        if(features=='')
            w=window.open(Url,name,'menubar=no,width='+width+',height='+height+'status=no,location=no')
        else	
            w=window.open(Url,name,'menubar=no,width='+width+',height='+height+',status=no,location=no,'+features)
        if (w != null) {
            w.focus()
        }
        return(w)
    }
 

Open a JQuery Tab from another link on the same page.

March 12, 2011 by admin No Comments »

Here is a nice little command you can use to open a jQuery Tab from another link or event raiser on the same page.
The method uses selectors so you will obviously need to know the tab(s) container ID or css class name and also the index or id/css class for the tab itself.

Using ID:

      $("#TAB_CONTAINER_ID").tabs("select", TAB_INDEX/TAB_ID);
 

Get reponse headers from Ajax Request

August 14, 2010 by admin No Comments »

If you are using Ajax to make requests and want to get response headers from the last request here is how:

This will return all the headers in the request. I assume ‘xhr’ is your XMLHTTPRequest object.

xhr.getAllResponseHeaders();

If you want to get a specific header item such as Content-Type, here is how

xhr.getResponseHeader('Content-Type');
 

toggleMenu not defined error in Magento

August 9, 2010 by admin 6 Comments »

I have run into this error after an upgrade to magento 1.4.1.1

toggleMenu not defined.

This is a Javascript error and is to my suprise why it’s there in the first place!

Anyway, here is a temporary solution hoping Magento will one day decide to fix it!

Navigate to pp/code/core/Mage/Catalog/Block/Navigation.php file

Around line 246: replace

$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';

with

$attributes['onmouseover'] = 'Element.addClassName(this, \'over\')';
$attributes['onmouseout'] = 'Element.removeClassName(this, \'over\')';

Drop a line if you have any cleaner solution!

NOTE:
They say practice makes it perfect! Instead of editing your core files as above please use the approach below as its a lot more cleaner than the one above:
You can add this Javascript code in one of your javascript files that are used across the site.

function toggleMenu(el, over)
{
    if (over) {
        Element.addClassName(el, 'over');
    }
    else {
        Element.removeClassName(el, 'over');
    }
}
 

Wrong Javascript/CSS paths magento after moving to new server

April 29, 2010 by admin No Comments »

Here is how to solve this problem:

Make sure the media/js directory belongs to the same user as the Magento folder
Clean the CSS/Javascript cache in the administration area

 

Magento Admin page loosing Javascript URL paths

April 15, 2010 by admin No Comments »

Strange thing happened to me while moving magento from local machine to live server.

Magento admin pages could not load javascript files successfully hence the admin pages misbehaved greatly.

To fix it, Add the following to the core_config_data table; (If exists already, set the value to 0)

              scope_id=0
              path =  "/dev/js/merge_files"
              value = 0