Modals doesn't work with URLs if URL already...

Search
Other Bug Reports questions
Forum

Modals doesn't work with URLs if URL already contains a parameter

Mike Prince's Avatar Mike Prince
The URL provided is automatically appended "?ml=1" which results in something like
https://example.com/?p=1?ml=1
rather than being appended with an ampersand in this case
https://example.com/?p=1&ml=1
Peter van Westen's Avatar Peter van Westen ADMIN
Do you have this online so I can take a look?
Please post a rating at the Joomla! Extensions Directory
Mike Prince's Avatar Mike Prince
It's behind a login so I just created a simple article and no ml parameter was added, and it worked fine.
In my code I'm dynamically creating a URL in JavaScript so it's more complicated. I've created a test based on this at staging.panspecieslisting.com/test.html which uses the following code.
<p id="test"></p>
<script>
var txt = "Test";
var url = "https://example.com?p=1";
var link = '<a href="' + url + '" class="popup" title="Test">' + txt + '</a>';
document.getElementById("test").innerHTML = link;
</script>
This does get the ml parameter added to form the invalid URL.
Peter van Westen's Avatar Peter van Westen ADMIN
Not sure why you are trying to insert a link via javascript like that. But try 'breaking' the link:
<p id="test"></p>
<script>
var txt = "Test";
var url = "https://example.com?p=1";
var link = '<' + 'a href="' + url + '" class="popup" title="Test">' + txt + '</a' . '>';
document.getElementById("test").innerHTML = link;
</script>
Please post a rating at the Joomla! Extensions Directory
Mike Prince's Avatar Mike Prince
With that version (correcting the '.' with a '+') it isn't converted to a modal at all.

That example is a bit silly but it's just a test: in the actual code the URL is constructed dynamically based on the result of an Ajax callback.
Peter van Westen's Avatar Peter van Westen ADMIN
The Modals script runs on pageload. So if you dynamically add links to the output, you'll need to run the Modals init command after adding them:
RegularLabs.Modals.init();

I recommend you first create a normal Modals link using the {modal} tags, and see what raw html output that generates (via the html output, not the element inspector). Then mimic that in your script.
Please post a rating at the Joomla! Extensions Directory
Mike Prince's Avatar Mike Prince
Ok, I've used the raw output and got it working with that, e.g.
<a data-modals href="https://example.com?p=1&ml=1" data-modals-height="100%" data-modals-width="100%">Test</a>
Thanks for your help.
You can only post on this forum if you log in