Skip to main content

Posts

Showing posts from March, 2014

window.onbeforeunload ajax request problem

From last few hours I was facing a problem with window.onbeforeunload . My need was to save form data(partial saving) by ajax, in case user opts to close the browser, reload the window or close the window. I was using following code : //Old Code window.onbeforeunload = function () {               saveFormData();    return msg; }; It was saving my content but the return statement was showing me a confirmation message with options ‘ Leave Page ’ and ‘ Stay on Page ’. It was so embarrassing. Without return statement it was not saving my data at all. After spending lot of time on internet and brainstorming a little found the following solution: //New Code $(window).bind('beforeunload', function () {                  //this will work only for Chrome                 saveFormData(); }); $(window).bind("unload", function () {   //this will work for other browsers  saveFormData(); }); It worked like a charm for me. Hopefully it

Magento : Add “Subscribe to Newsletter” checkbox on Contact Form

To add "Subscribe to Newsletter" checkbox on Contact form, follow following steps:  1) Go to contacts/form.phtml file of your selected theme. 2) Place following code in the file as per your requirement :     <input type="checkbox" name="subscribe_newsletter"><?php echo          Mage::helper('contacts')->__(' Subscribe to Newsletter ') ?> 3) Now go to \app\code\local\Mage\Contacts\controllers\IndexController.php file      and put following code in postAction() function :     Note: If you are not able to find Mage/Contacts.... folder in local directory please create new one and refer to the link ( http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_a_local_copy_of_app_code_core_mage )  /*Start of code*/             if(isset($_POST['subscribe_newsletter'])){                         $email = $_POST['email'];      

Magento 1.7 not showing Google Analytics code in application.

Recently, faced an issue with Google Analytics code implementation in Magento version 1.7. Done with all the settings to implement Google Analytics, still it was not showing Google Analytics code in my Magento application. Searched a little and came up with following solution. Go to \app\design\frontend\default\mytheme\layout\googleanalytics.xml file : Replace <reference name="after_body_start">         <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" /> </reference> Code Block  With <reference name="after_body_start">         <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" template = "googleanalytics/ga.phtml" />   </reference> Above code worked for me. Hopefully it will work for others as well. Thanks!!!!!!!!! Enjoy Programming :)