Search
Other Sourcerer questions
Forum

Absoulute URL Link to external site always prepended with source site

Huw's Avatar Huw
Hi I have created a simple API to get table data from one site and then show it on another.
When i load the API code into a html page then the link to the event works.
Confidential information:
(hidden)

When i load the same code into a joomla module using sourcerer the link to the event is alway prepended with the website that it has been loaded onto.
Here is my code:
<div id="event-container"></div>

<script>
// API URL
const apiUrl = "https://esci.ie/escievents.php?api_key=secret"; // Replace with your API URL and key

// Fetch event data
fetch(apiUrl)
  .then(response => {
    console.log("Raw Response:", response); // Debugging step
    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    }
    return response.json();
  })
  .then(data => {
    console.log("Parsed Data:", data); // Debugging step
    if (data.status === "success") {
      const event = data.data[0]; // Adjust index for desired event
      
      // Extract required fields
      const id = event.id;
      const title = event.title;
      const eventDate = event.event_date;
      const eventEndDate = event.event_end_date;
      const shortDescription = event.short_description;
      const individualPrice = event.individual_price || "Free";

      // Generate link
      const eventLink = `https://esci.ie/index.php?option=com_eventbooking&view=event&id=${id}`;

      // Render HTML
      const eventHTML = `
        <div class="event">
          <h3>${title}</h3>
          <p><strong>Start Date:</strong> ${new Date(eventDate).toLocaleDateString()}</p>
          <p><strong>End Date:</strong> ${new Date(eventEndDate).toLocaleDateString()}</p>
          <p><strong>Description:</strong> ${shortDescription}</p>
          <p><strong>Price:</strong> €${individualPrice}</p>
          <a href="${eventLink}" target="_blank" rel="noopener noreferrer">View Event</a>
        </div>
      `;

      // Insert into the page
      document.getElementById("event-container").innerHTML = eventHTML;
    } else {
      document.getElementById("event-container").innerText = "Failed to load event data.";
    }
  })
  .catch(error => {
    console.error("Error fetching the event data:", error);
    document.getElementById("event-container").innerText = "Error loading event data.";
  });
</script>

The <a href="${eventLink}" target="_blank" rel="noopener noreferrer">View Event</a> part despite loading an absolute url always gets prepended like this:
www.website1.com/https://esci.ie/index.p...king&view=event&id=1
Any ideas how to fix this?
Huw's Avatar Huw
I can confirm this is joomla behaviour rather than an issue with sourcerer.
If i turn off TinyMCE then paste in my code using the code editor in joomla, then my links are still being prepended with the site url.
I set the module to prepare content = yes
I will try some other methods and see what i can achieve.
I really dont want to use an iframe....
Peter van Westen's Avatar Peter van Westen ADMIN
Make sure your SEF system plugin is ordered as one of the last.
See: regularlabs.com/blog/242-plugin-order-is-important
Please post a rating at the Joomla! Extensions Directory
Huw's Avatar Huw
Thanks for the reply Peter.
I just did that and cleared the cache - unfortunately still the same issue. The Absolute URL's are being prepended by the site URL.
I also disable SEF Urls but again that made no difference!
Peter van Westen's Avatar Peter van Westen ADMIN
Check what the javascript code looks like in the html output of your site.

PS: This has nothing to do with Sourcerer, but with your javascript and how Joomla handles urls in the output.
Please post a rating at the Joomla! Extensions Directory
Huw's Avatar Huw
Ok I solved this:
const eventLink = `href ="${esciURL}index.php?option=com_eventbooking&view=event&id=${id}"`;

<a ${eventLink}>View Event</a>
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription