We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17183
    • 20 Posts
    Hello, I want ask a thing for MODx tag which is putted out by JavaScript.

    I wrote JavaScript code at MODx document likes under.

    var MODx_id = 28;  //Document ID
    var JS_Link = ’<a href="[~’ + MODx_id + ’~]">’ + LinkLabel + ’</a>’;
    document.writeln ( JS_Link );


    As a result, the page displays the code likes under,

    <a href="[~28~]">LinkLabel</a>

    So I want to change <a href="[~28~]">LinkLabel</a> to <a href="domain/documentURL">LinkLabel</a>.
    How can I do it ?

    (I’m sorry for that my English not good :’( )
      • 22303 MODX Staff
      • 10,725 Posts
      You need the Javascript to be generated with the MODx tags on the server-side. It will not work from Javascript you dynamically insert into the page once the page is delivered to the client.

      You would put in your content:
      var JS_Link = '[~28~]';
      

      That will insure that the URL is generated server side, rather than the tag being put together after the page is delivered, which is meaningless to the browser and your Javascript code.
        • 17183
        • 20 Posts
        Ou ! It’s a nice advice !! I can do it !
        Thank you very much !!