{link} breaks javascript

  • Hi,

    I've uploaded a free package to the Woltlab plugin-Store and it is being reviewed.

    From this review, I received following feedback:

    Zitat von TimWolla

    Your change with the {link} template plugin is invalid. Look at the output that's being generated if a session id is being appended: "document.location.href='http://example.com/?jcoinsbuy/&country='+this.value&s=b593733907c12f7e5e4238ca1d2b1d87442ba7b4"It causes a JavaScript error!


    Questions:
    1) On my site no session is being added. In which use case does Woltlab add this so I can test it?
    On my site: <select onchange="document.location.href='/JCoinsBuy/?country='+this.value">

    2) How can I fix this issue?
    This is the line in the template file:

    Code
    <select onchange="document.location.href='{link controller='JCoinsBuy'}country='+this.value{/link}">


    Many thanks!

    • Offizieller Beitrag

    Hi

    In which use case does Woltlab add this so I can test it?

    It gets added if:

    • The session is new and Community Framework could not yet determine whether Cookies are supported
    • Cookies are not supported or disabled

    The code can look something like this:

    Code
    {capture assign=jcoinsBuyLink}{link controller='JCoinsBuy' encode=false}{/link}{/capture}
    <select onchange="document.location.href='{$jcoinsBuyLink|encodeJS}{if $jcoinsBuyLink|strpos:'?' !== false}&{else}?{/if}country='+this.value;">
  • Ok, so this worked for quite a while, but now I received a bug report on this code.

    The code:

    Code
    {capture assign=jcoinsBuyLink}{link controller='JCoinsBuy' encode=false}{/link}{/capture}
    <select onchange="document.location.href='{$jcoinsBuyLink|encodeJS}{if $jcoinsBuyLink|strpos:'?' !== false}&{else}?{/if}country='+this.value;">


    The issue:
    On a user's website this link redirects to:
    site.de/JCoinsBuy/

    While the actual url on his installation is:
    site.de/index.php/JCoinsBuy/

    For me it is working, as I am using the SEO package to remove the index.php
    He is not using this SEO package.
    I would expect the controller to create the link correctly, but apparently it does not.

    Any idea what could be the cause and how to make it work in both SEO and non-SEO optimised websites?

    Thank you!

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!