Support » Plugin: WP Edit » WP Edit – Preventing WordPress from stripping out onclick Javascript

  • Resolved paorganic

    (@paorganic)


    Greetings!

    I’ve been trying to implement some Javascript and related PHP scripts on our site from a document management suite we use (DocMoto). What I’m trying to do is on our WordPress site, rather than using a plugin to store our documents there and have clients/general public access them there, to instead access them in a guest mode from our DocMoto server. This also helps make sure we have the most current version as it’s only accessing our controlled docs and we don’t have to make sure what is on the website is up to date and matches DocMoto.

    Anywhooo…the Javascript function I’m trying to implement uses onclick and that gets stripped out when I flip from the Text back to the Visual editor. That part I figured out was part of the TinyMCE issue…thus that brought me to your plugin.

    How do I setup your plugin so that it will allow me to use the Javascript onclick in this example…

    onclick=”getDMFile(‘http://mydocmotoserver.com:3983/Contents/Folder1/company_brochure.pdf’)

    The example can be found here:
    http://www.docmoto.com/support/advanced-topics/anonymous-file-access-to-a-docmoto-repository/

    Thanks!

    https://wordpress.org/plugins/wp-edit/

Viewing 15 replies - 1 through 15 (of 39 total)
  • Plugin Author Josh

    (@josh401)

    Hello.

    Actually, javascript is not meant to be ran from the content editor. That is why WordPress is stripping out the onclick event you are adding. The free version of this plugin won’t prevent the editor from stripping out the onclick event.

    You have two options:

    1) Use a plugin like Scripts and Styles to add your javascript to the page where you are using the onclick event. Then, add a click event in your javascript code, referencing the class or id of the element.

    2) You can use some custom code from a child theme; and allow the editor to prevent the stripping of the onclick attribute.

    Which approach would you prefer?

    paorganic

    (@paorganic)

    Ok…

    I have the plugin, CSS & Javascript toolbox which lets me add the code specifically to the page I want it on, however for starters it that code literally shows up in the footer or header of the page, I must be misunderstanding how to implement it.

    Also, I’m sorry I don’t quite understand adding a click event to the code and referencing the class or ID of the element.

    I was given the client side Javascript which is (this is what’s showing up in my header/footer:

    //This function takes the URL from the link anchor
    //and sends it to the php script.

    function getDMFile(myURL)
    {
    window.location.href = “getDMFile.php?fileURL=” + myURL;
    return false;
    }

    And then I have the onlick Javascript which they say “is called from a hyperlink (anchor) within the web page.”

    Sorry…I know we are moving outside the realm of your plugin to something else so no worries if you can’t help. Your response back does give me a bit more direction as it is…thanks for that!

    Plugin Author Josh

    (@josh401)

    No worries. I’m happy to help.

    Well, WordPress works a little differently than a static HTML site (which is what your javascript is written for).

    My first question… what exactly are you trying to do? Your code references a file called getDMFile.php. Do you have this file? Have you uploaded it to your server?

    paorganic

    (@paorganic)

    Yes, I have the php file…the vendor provided it all, along with the documentation I linked…but as they are not WordPress developers they can’t / won’t help with implementing it.

    For the PHP, I’m then using the plugin “PHP Code” (https://wordpress.org/plugins/php-code-for-posts/) as I wasn’t totally sure/comfortable adding it via the cpanel. Might that also be an issue?

    What the end goal is instead of using our current Download Monitor plugin, which stores hundreds of documents that we want our clients and website visitors to access, I’m making use of the Javascript and PHP files DocMoto has provided so that I can instead embed the links directly to where these controlled documents are stored…our DocMoto server, which our inhouse staff can access using their Mac application.

    The issue has been we have to make sure the documents we’ve uploaded on the website match what’s in DocMoto…these are updated quite often and many times, no one tells me so that I can update what we have on the website.

    The end goal is once this is setup, I just create the href / anchor link once on our Documents page on the WordPress site, and the javascript/php take care of accessing the most up to date file from DocMoto.

    Does that help at all…clear as mud? 😉

    Thanks!

    paorganic

    (@paorganic)

    Ok, I was able to upload the 2 required PHP files to our host provider (with the small changes that define our unique server and guest login). I dropped them right in the public/html directory hope that was correct. So I won’t be using that plugin I’d mentioned above for the PHP.

    So I guess the issue will be as you pointed out, how I “add your javascript to the page where you are using the onclick event. Then, add a click event in your javascript code, referencing the class or id of the element.”

    Josh,

    To followup, to your statement about a month ago…”The free version of this plugin won’t prevent the editor from stripping out the onclick event.”

    Will the paid version?

    Plugin Author Josh

    (@josh401)

    I feel like an a**. Every time I came back here to follow up… I got the feeling like maybe you had moved on…. and then I’d get involved doing something else…

    Anyways… my apologies.

    Now, let’s get your working.
    Please use my contact form and we can deal with this via email (include a link to this topic, so I know who you are). You don’t need to purchase pro… we’ll do a little custom coding 🙂

    Talk to you soon.

    Plugin Author Josh

    (@josh401)

    Just following up. Did you ever send me an email?

    Josh,

    Sorry…I didn’t see your post from last week…not sure why it didn’t ping me when you wrote it…now time for me to apologize!

    I’ll send it most likely Friday…much appreciate the help!

    Joshua

    Plugin Author Josh

    (@josh401)

    Got it.
    Thanks mate.

    Sure thing…thank you…it’ll be nice to hopefully get this up and running so I don’t have to manually check the website vs our document management software to make sure the website has the most up to date documents.

    Plugin Author Josh

    (@josh401)

    I’ve got your email.

    I think we need to have a quick chat on the phone 🙂

    I’ll reply back to your email with my phone number. Call me at your convenience 🙂

    Thanks…will do!

    Plugin Author Josh

    (@josh401)

    Thanks.

    I wanted to swing back here and give an enormous round of kudos to Josh. In the end, we didn’t end up using his own stellar plugin, WP Edit, Josh took the time and effort to debug a solution we were provided by our document host provider, rewrite it, and get it up and running to give us EXACTLY what we needed.

    Josh worked with us, the developers of our controlled document system, our hosting provider…he might’ve even reached out to Obama I’m not sure 😉 …. and got it done.

    I cannot recommend his work enough! If you’re coming across his plugin and this thread…you’ve made the right choice!

    Joshua J. Brock
    Technology Coordinator
    Pennsylvania Certified Organic

Viewing 15 replies - 1 through 15 (of 39 total)
  • The topic ‘WP Edit – Preventing WordPress from stripping out onclick Javascript’ is closed to new replies.