Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Putting Javascript in a Wordpress file (not a post) in the Body (not the head)

Posted on 2009-04-04
6
Medium Priority
?
473 Views
Last Modified: 2012-06-27
I need to put javascript in the body of a Wordpress page.  It's not a blog or a post, but a  page.

As you know, apparently by default, Wordpress adds // to the javascript which prevents it from working (apparently for security reasons.)

It's for a "Thank you" page that needs the javascript in the body, and not int he head of the page.

Any suggestions?

Thanks

Rowby

 
<script id="pap_x2s6df8d" src="http://www.blahblah.net/affiliate/scripts/salejs.php" type="text/javascript">
</script>
<script type="text/javascript">
var sale = PostAffTracker.createSale();
sale.setTotalCost('1.0');
sale.setOrderID('ORD_12345XYZ');
sale.setProductID('test product');
PostAffTracker.register();
</script>

Open in new window

0
Comment
Question by:Rowby Goren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:dosth
ID: 24067897
let me clear my self, so you created a thank you page and their you need to put the javascript, if so what is they issue you are facing. you can directly add this script.

can you tell me the issue?

thanks
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 24072472
Hi dosth

The problem is, when you paste javascript into the - body - of a file Wordpress automatically adds "\\" to the code apparently for security reasons.  This breaks the javascript code -- as you can see in my below snippet.
Below is what I pasted into the source code of my wordpress thank you page CODE tab:
 
<script src="http://www.blahblah.net/affiliate/scripts/salejs.php" id="pap_x2s6df8d" type="text/javascript"> </script>
<script type="text/javascript"> var sale = PostAffTracker.createSale(); sale.setTotalCost('1.0'); sale.setOrderID('ORD_12345XYZ'); sale.setProductID('test product'); PostAffTracker.register(); </script>
 
As soon as I saved it you will see below that Wordpress automatically added escapes "\" throughout the javasctipt.  This breaks the javascript.  And if I save it again it adds another \ to the javascript."  :(
 
 
<script src="http://www.blahblah.net/affiliate/scripts/salejs.php" id="pap_x2s6df8d" type="text/javascript"> </script><br />
<script type="text/javascript"> var sale = PostAffTracker.createSale(); sale.setTotalCost(\'1.0\'); sale.setOrderID(\'ORD_12345XYZ\'); sale.setProductID(\'test product\'); PostAffTracker.register(); </script>

Open in new window

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 24074021
Hello

Any other experts with a solution to this Javascript issue?

Thanks

Rowby
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 15

Accepted Solution

by:
dosth earned 2000 total points
ID: 24074274
it will add when you do this via the wp-admin, if the thankyou page is your custom page, you can add it via any FTP tool. otherwise do this.

1. copy the js code to a include file
2. copy the inculde file to you thank you page.

you can see steps here

http://www.webreference.com/programming/javascript/external/
0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 31566567
Thanks for the solution and the links!  ...Rowby
0
 
LVL 15

Expert Comment

by:dosth
ID: 24122627
thanks for the points
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question