Title: Link with Javascript in it
Last modified: August 16, 2021

---

# Link with Javascript in it

 *  [marou10](https://wordpress.org/support/users/marou10/)
 * (@marou10)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/)
 * Hi,
 * I have a link wich have this format :
    `<a href="javascript:xxxxxxx();">My Link
   </a>` How can I prevent phastpress to desactivate it ?
 * Thanks
    -  This topic was modified 4 years, 9 months ago by [marou10](https://wordpress.org/support/users/marou10/).
    -  This topic was modified 4 years, 9 months ago by [marou10](https://wordpress.org/support/users/marou10/).

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Albert Peschar](https://wordpress.org/support/users/kiboit/)
 * (@kiboit)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14776777)
 * Hi [@marou10](https://wordpress.org/support/users/marou10/),
 * This should work fine with PhastPress.
 * Can you share the URL of the site where you’re experiencing this problem and 
   tell me which link is not working?
 * –Albert
 *  Thread Starter [marou10](https://wordpress.org/support/users/marou10/)
 * (@marou10)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14778990)
 * Hi !
    Thanks for your answer.
 * It is not working fine.
    Seems to be this setting which is the problem with the
   link : “Load scripts asynchronously”
 * Unfortunateley, the site is not live. Work in progress. So I can’t give the link
   publicly
 * But to be more precise, this link is for openning the cookie pannel :
 *     ```
       <a href="javascript:tarteaucitron.userInterface.openPanel();">
       ```
   
 * Do these informations help ?
 *  Plugin Author [Albert Peschar](https://wordpress.org/support/users/kiboit/)
 * (@kiboit)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14779042)
 * Hi [@marou10](https://wordpress.org/support/users/marou10/),
 * There’s probably no issue with the link itself, but the script providing the 
   called function `tarteaucitron.userInterface.openPanel();` is not loaded for 
   some reason.
 * You can use the contact details at the bottom of the plugin description to share
   the link only with me, if you’d like me to debug the issue.
 * –Albert
 *  [Amauri](https://wordpress.org/support/users/amauric/)
 * (@amauric)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14779425)
 * If it can help, [https://tarteaucitron.io/load.js?xxx=yyy](https://tarteaucitron.io/load.js?xxx=yyy)
   have to be loaded in the head without async or defer 😉
 *  Plugin Author [Albert Peschar](https://wordpress.org/support/users/kiboit/)
 * (@kiboit)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14779771)
 * Hi [@amauric](https://wordpress.org/support/users/amauric/), [@marou10](https://wordpress.org/support/users/marou10/),
 * I can’t test here because PhastPress is disabled. Understandably so, if it breaks
   your site. 😉
 * But could you enable the plugin, and in the plugin settings disable the optimizations?
   It’s the first setting. This way it’ll be disabled for your visitors but can 
   be tested when I add `?phast=phast` to the URL.
 * –Albert
 *  Plugin Author [Albert Peschar](https://wordpress.org/support/users/kiboit/)
 * (@kiboit)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14783222)
 * Hi [@amauric](https://wordpress.org/support/users/amauric/), [@marou10](https://wordpress.org/support/users/marou10/),
 * The issue is with the way that tarteaucitron.js determines its own URL. It uses
   a technique like this:
 *     ```
       var scripts = document.getElementsByTagName("script");
       var url = scripts[scripts.length - 1].src;
       ```
   
 * This will get the URL of the last script on the page. Normally, this works fine,
   because the last script in the DOM is the one that is currently executing (the
   rest of the page has not yet been parsed).
 * But when using PhastPress this does not work. Before scripts are executed, the
   entire page is loaded, so the last script will always be the same, and not the
   one that is currently executing.
 * Instead of using this technique, I would recommend doing this:
 * `var url = document.currentScript.src`
 * This won’t work in IE, so you might do this:
 * `var url = (document.currentScript || scripts[scripts.length - 1]).src`
 * For the current situation you may define the variable `tarteaucitronForceCDN`
   to tell tarteaucitron.js where to find its resources. You need to do this before
   loading the tarteaucitron.js.
 * You can do this by adding this code to your plugin:
 *     ```
       add_action('wp_print_scripts', function () {
         printf(
           "<script>tarteaucitronForceCDN=%s</script>\n",
           json_encode("https://cdn.jsdelivr.net/gh/AmauriC/tarteaucitron.js@1.9.1/")
         );
       });
       ```
   
 * You may replace the URL with a variable so you don’t repeat it when loading the
   script itself and it’s easier to update the version, but that’s up to you.
 * Hope this helps, and good luck!
 * –Albert
 *  Thread Starter [marou10](https://wordpress.org/support/users/marou10/)
 * (@marou10)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14783679)
 * Hi,
 * Not sure I understand everything you said…
    I’m too beginner for that.
 * But I have to thank you very much for your help and kindness !
 *  [Amauri](https://wordpress.org/support/users/amauric/)
 * (@amauric)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14783913)
 * Thanks a lot [@kiboit](https://wordpress.org/support/users/kiboit/) for your 
   debug!
 * An issue is opened on [https://github.com/AmauriC/tarteaucitron.js/issues/779](https://github.com/AmauriC/tarteaucitron.js/issues/779),
   it will be fixed 😉

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Link with Javascript in it’ is closed to new replies.

 * ![](https://ps.w.org/phastpress/assets/icon-256x256.png?rev=1873505)
 * [PhastPress](https://wordpress.org/plugins/phastpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/phastpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/phastpress/)
 * [Active Topics](https://wordpress.org/support/plugin/phastpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/phastpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/phastpress/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [Amauri](https://wordpress.org/support/users/amauric/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/link-with-javascript-in-it/#post-14783913)
 * Status: not resolved