Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am wondering if anyone may know a quick fix to this issue. Right now while applying a single javascript to a WordPress block its working fine.

Once adding a second widget with similar code then it's causing some type of conflict with the first one.. perhaps this may be because they are using the same name or sharing some type of information.

I'll post both code snippets below & you may know a way to completely separate them so they do not recognize each-other and conflict.

These buy now Java script buttons from Xsolla & they each have different values, I need to add a total of 10 12 but right now I cannot add more than one without some type of conflict.

Code 1: var options = { access_token: 9upbu4RrjLChk8PgP42n5LqSmqANijKY, theme : { foreground: green, background: dark }, lightbox: { height: 700px, spinner: round }, target_element: #XS-pay2play-widget }; var s = document.createElement(script); s.type = text/javascript; s.async = true; s.src = https://cdn.xsolla.net/embed/pay2play/2.3.0/widget.min.js; s.addEventListener(load, function (e) { var widgetInstance = XPay2PlayWidget.create(options); }, false); var head = document.getElementsByTagName(head)[0]; head.appendChild(s);

Code 2: var options = { access_token: 9upbGoqnbonvXqyfgaBtsDcyWnv0FXEe, theme : { foreground: green, background: dark }, lightbox: { height: 700px, spinner: round }, target_element: #XS-pay2play-widget }; var s = document.createElement(script); s.type = text/javascript; s.async = true; s.src = https://cdn.xsolla.net/embed/pay2play/2.3.0/widget.min.js; s.addEventListener(load, function (e) { var widgetInstance = XPay2PlayWidget.create(options); }, false); var head = document.getElementsByTagName(head)[0]; head.appendChild(s);

The blog I need help with is https://www.legioneternalwar.com/crowdfunding/ You can see a buy button below and there is a spouse to be a buy button for all packages but they are conflicting with each other.

What I have tried:

Code 1: var options = { access_token: 9upbu4RrjLChk8PgP42n5LqSmqANijKY, theme : { foreground: green, background: dark }, lightbox: { height: 700px, spinner: round }, target_element: #XS-pay2play-widget }; var s = document.createElement(script); s.type = text/javascript; s.async = true; s.src = https://cdn.xsolla.net/embed/pay2play/2.3.0/widget.min.js; s.addEventListener(load, function (e) { var widgetInstance = XPay2PlayWidget.create(options); }, false); var head = document.getElementsByTagName(head)[0]; head.appendChild(s);





Code 2: var options = { access_token: 9upbGoqnbonvXqyfgaBtsDcyWnv0FXEe, theme : { foreground: green, background: dark }, lightbox: { height: 700px, spinner: round }, target_element: #XS-pay2play-widget }; var s = document.createElement(script); s.type = text/javascript; s.async = true; s.src = https://cdn.xsolla.net/embed/pay2play/2.3.0/widget.min.js; s.addEventListener(load, function (e) { var widgetInstance = XPay2PlayWidget.create(options); }, false); var head = document.getElementsByTagName(head)[0]; head.appendChild(s);
Posted
Comments
Richard MacCutchan 24-May-20 4:23am    
Please edit your code and break it into proper lines so it is readable. Also I notice that you are using the same names for the variables (options, s etc.) in both cases. Compilers are not clever enough to figure out which one you are referring to in either case. You must use unique names for variables within the same scope.
devilion98 24-May-20 4:41am    
Hello Sir, I'm a little bit new for this field if you don't mind can you explain this matter with more simplify it would be great.
Richard MacCutchan 24-May-20 5:01am    
How much simpler could it be? If you have two children and you call them both devillion99, how do you get only one of them to come when you call? It is the same with computer languages. If you have two variables in the same scope with the same name the compiler cannot tell which one you want to refer to at any time. And if you don't understand Javascript you can find plenty of tutorials on the internet. Here are two links that will help: JavaScript Tutorial[^] and JavaScript | MDN[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900