Support » Plugin: PhastPress » Link with Javascript in it

  • marou10

    (@marou10)


    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 2 months ago by marou10.
    • This topic was modified 2 months ago by marou10.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Albert Peschar

    (@kiboit)

    Hi @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

    (@marou10)

    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

    (@kiboit)

    Hi @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

    AmauriC

    (@amauric)

    If it can help, https://tarteaucitron.io/load.js?xxx=yyy have to be loaded in the head without async or defer 😉

    Plugin Author Albert Peschar

    (@kiboit)

    Hi @amauric, @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

    (@kiboit)

    Hi @amauric, @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

    (@marou10)

    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 !

    AmauriC

    (@amauric)

    Thanks a lot @kiboit for your debug!

    An issue is opened on https://github.com/AmauriC/tarteaucitron.js/issues/779 , it will be fixed 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.