Skip to main content

Questions tagged [javascript]

JavaScript (JS) is a client side script language which allows to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed. By default Magento 1 comes with the prototype.js library and Magento 2 comes with jQuery. Use 'prototype-js' and 'jquery' tags for questions about those libraries.

Filter by
Sorted by
Tagged with
42 votes
3 answers
89k views

Extending / Overriding JS in Magento 2

As Magento2 is using RequireJS for loading scripts, and there's no more skin folder, I've stuck with a problem: How can I replace Magento's module JS file by my modified version? For example — the ...
Dmytro's user avatar
  • 1,090
45 votes
8 answers
79k views

How To add JS file in frontend for all pages

I've read 3 pages of Google Results on how to load a JS file for all pages and still am not able to do it. I've got a few doubts, hope somebody can clear them out. Do I need to create a module ...
Prashant Akash's user avatar
16 votes
4 answers
30k views

PageSpeed - Eliminate render-blocking JavaScript and CSS in above-the-fold content

I am running magento 1.9, and I am using the RWD slider that comes with Magento 1.9 on the home page. Google's PageSpeed doesn't like this and says: Eliminate render-blocking JavaScript and CSS ...
styzzz's user avatar
  • 736
12 votes
6 answers
51k views

How to call Owl Slider in Magento2

If we want to add Owl Slider in Magento 1.X then we follow the below steps. Copy owl.carousel.min.js and owl.carousel.js and paste into skin/frontend/pakage_name/theme_name/js Copy owl.carousel.css ...
Dhaval's user avatar
  • 1,695
36 votes
7 answers
37k views

Move all Javascript includes to before </body>

Does anyone know how to have all of Magento's JS script tags e.g. <script type="text/javascript" src="http://sitename.com/js/prototype/prototype.js"></script> render out before the closing ...
Mark Weston's user avatar
39 votes
1 answer
15k views

Product.OptionsPrice is not a constructor magento 1.9.3

I have upgrade magento 1.9.2.4 to 1.9.3. I am facing the following error in the console in product page. TypeError: Product.OptionsPrice is not a constructor var optionsPrice = new Product....
Denish Vachhani's user avatar
4 votes
1 answer
3k views

Unable to use jQuery

Alright, I am trying to do a very simple thing: use jQuery in my myScript.js file. I'm on Magento 1.9.0.1. The theme I am building is based on the built-in rwd theme, which by default loads jQuery 1....
Ezratic's user avatar
  • 157
16 votes
1 answer
11k views

Magento2: How can I override core js module price-box.js

I need to extend Magento_Catalog/js/price-box.js. I have used the 'mixins' feature, but it's not working for price-box.js. requirejs-config.js: var config = { config: { mixins: { ...
Yogesh Karodiya's user avatar
16 votes
3 answers
34k views

How to add external js in Magento 2

I want to add the following link in the head tag, but its returning 404 error. Can anyone help me on this? <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></...
Sivakumar K's user avatar
  • 2,013
15 votes
3 answers
18k views

Get Base Url Or Dynamic Url In view Js or html files

I figure it out to get dynamic url in the front end if I need I can simply define mage/url and the use it as url.build('<Modulename>/<controllername>/<action>/') When I tried the ...
Priyank's user avatar
  • 7,702
3 votes
2 answers
20k views

Adding JS to the checkout

How to add custom JS to just the checkout page? I found this tutorial, but as far as I can tell it will add JS to the entire site.
Metal Mathematician's user avatar
24 votes
12 answers
32k views

Merged JS and CSS do not work when Production mode

I was in developer mode, everything was great, when I changed to Production mode, the Merged options of CSS and JS seem to be ignored, it was back listing all css and js. Also the product page only ...
user37025's user avatar
  • 1,383
18 votes
2 answers
9k views

Google CDN jQuery with Local Fallback in Magento Layout XML

I've done the following to include jQuery from Google CDN in Magento: <default> <reference name="head"> <block type="core/text" name="google.cdn.jquery"> <...
philwinkle's user avatar
  • 35.8k
11 votes
3 answers
14k views

JS errors Magento 2

I've been trying to finish something and publish it online this entire weekend, it's some how broken and I have no idea why so I hope someone can help me out. I've tried adding custom jQuery into my ...
magin's user avatar
  • 515
7 votes
2 answers
32k views

Add custom js in head in magento2?

I have custom module. I want add file my.js in folder app\code\Xanka\Slider\view\frontend\web\js\slider\my.js. I used code in app\code\Xanka\Slider\view\frontend\layout\default.xml <head> &...
xanka's user avatar
  • 2,114
6 votes
3 answers
8k views

Magento 2 add script before closing body tag

What is the proper way to add a script before the closing body tag in magento 2? I want it to be available to all pages. UPDATE: I've got in myvendor/mytheme/Magento_Theme/layout/default.xml with: ...
Matt's user avatar
  • 285
6 votes
1 answer
17k views

Magento 2: How to include JS on the product page?

I'm trying to get a custom js on the product page, I'm using Magento 2, what's the page I need to edit to do that? I've already tried to create a local.xml into /app/design/frontend/Venustheme/yume/...
alexcr's user avatar
  • 1,487
5 votes
3 answers
6k views

Custom javascript not working

I'm trying to inject a scroll to anchor javascript globally in Magento 2. More specifically this script: $('a[href^="#"]').on('click', function(event) { var target = $(this.getAttribute('href'));...
John's user avatar
  • 222
26 votes
4 answers
27k views

Magento 2: requirejs-config.js in themes?

Is it possible to include a requirejs-config.js file (or otherwise configure RequireJS) via a Magento theme? Or is the capability reserved for Magento modules? The dev docs information on theme ...
Alana Storm's user avatar
  • 44.4k
17 votes
4 answers
5k views

Magento2 localisation Javascript

A similar question was already asked here: Magento 2 javascript text translations, but Magento updated this translation technique in the beta version. How can I add or update translations used by ...
Silvan's user avatar
  • 1,347
12 votes
2 answers
63k views

How to add a custom javascript to theme in Magento 2?

I have experience with Magento 1, and there adding a custom javascript file was very straightforward and logical. But when it comes to Magento 2, I can't figure out how to add a new js file, where I ...
raouaoul's user avatar
  • 307
11 votes
9 answers
34k views

Magento 2: Not loading CSS and JS after successful installation in windows

CSS and JS not loading after installation of Magento 2 default template OS: Windows 10 Xampp Control panel V3.2.2 PHP version: 5.6.28 Server: Apache/2.4.23 (Win32) phpmyadmin Version information: 4....
Amrith Prakash's user avatar
11 votes
6 answers
29k views

Magento 2 customer-data.js:90:23 [object Object]

I'm using Magento 2.2 with Porto theme and getting an [object Object] javascript error at customer-data.js line 90 in the console after logging into the store and refreshing the page or switching to ...
Lez's user avatar
  • 2,917
10 votes
4 answers
52k views

Use require-config.js to load files needed on all pages

I know how to use require-config.js in custom theme, but I would like to use custom javascript file (myfile.js) on all pages. In which directory should I add require-config.js and how to use it, so ...
Anitr's user avatar
  • 448
9 votes
4 answers
15k views

magento2 check if customer is logged in or not in knockout template

How do I check if customer is logged in or not in knockout template? my template <!-- ko if: customer().firstname --> <!-- /ko --> my js define( [ 'ko', 'jquery', ...
Nagendra Kodi's user avatar
8 votes
2 answers
2k views

Extend massactions.js

I need to extend a javascript from the new ui module that features the new admin grid system. Extend a default Ui component give me a hint, and I was able to setup some code: # file: app/code/My/...
Rafael Kassner's user avatar
6 votes
1 answer
5k views

Magento 2 Plugin implementation for js frontend?

A plugin as far as I read is created for intercepting a PHP function call and running code before, after, or around that function call. Is there a way how to accomplish that in js file? How can i ...
user3748173's user avatar
4 votes
4 answers
18k views

Defer parsing of JavaScript in Magento

i analyzed my website on Gmetrix.com for for optimization and the result was this: 361.0KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page ...
Moh3n's user avatar
  • 859
3 votes
1 answer
2k views

Call to a member function getAccountNo() on null Magento 2

I'm extending shipping method section in checkout page, and it's showing well. But it's throwing error while clicking next button after filling shipping address and shipping method information in ...
Bojjaiah's user avatar
  • 3,762
3 votes
1 answer
2k views

Changing the address book drop down (for shipping) from drop down list to radio buttons

I need to know how to change the address book drop down on a registered account checkout to radio buttons (similar to Amazon)
diz0pe's user avatar
  • 91
1 vote
2 answers
698 views

Magento 2: jQuery Datatables Button Extentions Not Working

============================UPDATED 1.1============================ I'm new to Magento 2.3, I'm trying to apply jQuery DataTable(DONE), after than, I want to add it's Button Extension, for that i ...
Partab Saifuddin Zakir's user avatar
1 vote
1 answer
982 views

Managing extension conflict on js files

I have and (community) extension that switches the product images when you change the options of a configurable product. This works great. I've also developed some extension that changes the select ...
Marius's user avatar
  • 198k
20 votes
2 answers
35k views

Custom form Validation - Magento

I am trying to implement some custom form validation in Magento using jQuery but I am not sure if I have the correct method. Basically, I need to validate the following: Only number fields need to ...
user1704524's user avatar
  • 2,483
17 votes
4 answers
24k views

Adding a jQuery Library to Magento 2

How can a third party developer add a jQuery library to Magento 2? While Magento 2 includes a version of jQuery in their frontend themes, the jQuery object is not immediately available in the global ...
Alana Storm's user avatar
  • 44.4k
16 votes
3 answers
11k views

Magento 2: Syncing Backend and Frontend State/Cache

Does Magento 2 have any systems or abstractions for managing state between the backend and the local storage on the frontend? I'm working on porting a feature for restoring a user's abandoned cart ...
Alana Storm's user avatar
  • 44.4k
10 votes
1 answer
23k views

How to use RequiredJS to execute the JS after the DOM ready?

I'd like to execute my JS after the DOM ready using RequiredJS instead of this: $(window).load()
Rafael Corrêa Gomes's user avatar
9 votes
1 answer
7k views

How to access the Magento API from native client with JavaScript

I need to access the Magento API from a local JavaScript based application (Titanium Desktop) and wondering what's the best way to do so. What I found out so far: The only authentication mechanism ...
Fabian Schmengler's user avatar
9 votes
3 answers
8k views

Magento 2: move the javascript to the end of the body

As Magento 2 migrated away from Prototype I was expecting that this would be fixed in M2. So, is there a way (easy or not) to move all the <script> tags to the end of the <body> tag ...
Raphael at Digital Pianism's user avatar
9 votes
5 answers
10k views

Magento2 getting 'Constr is not a constructor' error for custom theme

I am not sure what this error is and if it is affecting anthing, however this is coming into my console: layout.js:64 Uncaught TypeError: Constr is not a constructor (layout.js line 64)
PHPDev76's user avatar
  • 341
8 votes
3 answers
8k views

Uncaught TypeError: value.map is not a function coming from file-uploader.js

I am running Magento 2.2.3 When I try and go to admin/catalog/category/ and select a category it just spins and I get this javascript error. file-uploader.js:74 Uncaught TypeError: value.map is not ...
tjjen's user avatar
  • 883
7 votes
6 answers
21k views

How to use Javascript to display page messages

Is it possible to use JavaScript to display a page message? I would like to display one when I receive an ajax response on a custom module I'm working on. You can see an example of one of these ...
Holly's user avatar
  • 4,873
7 votes
4 answers
10k views

Magento 2: How to Solve Defer parsing of JavaScript on CDN?

My website in Production Mode & I set Javascript to be Merged. So we have only one JS file. On Speed related website it keep saying F grade on Defer Parsing of Javascript. I'm using CDN. <...
Jackson's user avatar
  • 9,939
6 votes
4 answers
12k views

Best Way Of Getting Base URL Inside KnockoutJS .html File

How can I get the base URL inside a KnockoutJS HTML file? See file below: app/design/frontend/<Vendor>/<Theme>/Magento_Checkout/web/template/<Filename>.html
Ryan Copeland's user avatar
4 votes
3 answers
9k views

Magento2: Add external JS globally

I'm trying to add external js in my module which will be applicable on all pages on frontend. This is the process I've followed: 1. Code in my layout file app/code/Lapisbard/General/view/frontend/...
amitshree's user avatar
  • 7,036
4 votes
2 answers
5k views

Configurable product image not switching with swatch change

I am trying to get configurable swatches working in a custom theme in a 1.9 build. I am basically using this method of importing the functionality in the theme. The swatches are working fine, they are ...
circlesix's user avatar
  • 4,303
3 votes
2 answers
8k views

How to add external JS to CMS Page

I'm trying to add an external javascript file to a CMS page using the Layout Update XML feature, and have had no luck. I have tried the following <action method="setText"><text><![...
John Quinones's user avatar
3 votes
1 answer
7k views

Magento 2 - Load custom javascript with requirejs

The Problem I want to use custom JavaScript in Products/Inventory/Catalog page to modify the "Add Product" button behavior and hide some fields in product edit form (where the SKU, weight, name, qty, ...
A. Martz's user avatar
  • 305
3 votes
2 answers
13k views

Magento admin failing to load CSS when SSL is activated

I've activated SSL for the whole Magento store and it works perfectly on the frontend, but the issues I'm having is with the admin. Once enabled, I can't access it. Before I had an issue with ...
Artur Rain's user avatar
3 votes
1 answer
7k views

Onepage checkout returns error 500 in Magento 1

I installed a theme in Magento 1 that is just working with onepage checkout. In general that is fine, but somehow it is not working. First, I type in my billing address/shipping address, but it stops ...
Safari's user avatar
  • 215
2 votes
3 answers
5k views

Magento 2 - Add step on checkout

I'm trying to add a new step to the normal workflow of magento 2 checkout, I follow the tutorial on magento dev page (http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_new_step.html) but ...
3tech - Alessandro Staffolani's user avatar

1
2 3 4 5 6