Guide to embedding an image from a third-party website using URL parameters to showcase a canvas or image

As a newcomer to Frontend Development, I have been struggling with a particular problem for the past two days. I am attempting to embed an image from an external source into an HTML page that I am building. Whether it is done through CSS as a background image or directly via HTML doesn't matter to me.

The source I am working with is within my control—a Github-Pages site that displays map snippets of a game at specific coordinates specified by parameters in the URL.

I create the image using a Canvas and have tried converting this Canvas to a PNG to display on the website's body. Unfortunately, no matter what I try, I cannot get it to display correctly with the necessary link.

Essentially, I need to be able to embed a link like this: githubpagessite.com?x=500&y=-500 in my code so that the displayed map position changes based on these parameters. The challenge lies in needing the parameters within the URL rather than having a direct link that redirects to the source as githubpagessite.com/....png.

I prefer resolving this issue using JS/HTML/CSS or jQuery exclusively. I have explored AJAX as a potential solution but haven't been successful in implementing it.

In further detail, my Github Pages site consists mainly of the following script (excluding unnecessary parts, focusing on image creation using canvas):

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const x = urlParams.get('x') //X coordinate retrieved from link
const y = urlParams.get('y') //Y coordinate retrieved from link

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

//images gets loaded etc. 

ctx.drawImage(images[0], coordinateXPosition, coordinateYPosition, snippedWidth, snippedHeight, 0, 0, snippedWidth, snippedHeight); 
//Image of the map gets drawn at the specific coordinate with a specific height.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>
<body>
    <canvas id="canvas" width="500" height="500"></canvas>
    <script src="script.js"></script>    
</body>
</html>

My goal is to utilize the querylink style mentioned above to embed two pictures with different coordinates on another site. However, the challenge arises because the request link does not lead to any PNG or JPG resource—this resource is only generated when the request link is sent and is temporary.

I aim to find a way to retrieve the dynamically created picture from the website. Initially, I considered using toDataURL() to transform the Canvas into a single image:

img src="data:image/png;base64,iVBORw0KGgoAAAANSUh....>

Hopefully, this clarification sheds light on the problem I am facing and will guide towards finding a suitable solution.

Answer №1

From my understanding, it seems like you are facing an issue with embedding an image from an external website onto this current page. In that case, you can utilize the following code snippet to resolve the problem:

<img src="https://www.exampleexternalwebsite.com/image.jpg">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Clicking on a date in the fullcalendar feature is not functioning properly

When using the fullcalendar plugin, I am experiencing an issue where the date is not initially selecting when clicked. However, if I click on the date again, it then gets selected as expected. $('#calendar').fullCalendar({ header: { left: ...

React-NextJS encountered an error: TypeError, it cannot read the property 'taste' because it is undefined

Recently, I've been encountering an issue with NextJS that keeps throwing the error message: TypeError: Cannot read property 'taste' of undefined. It's quite frustrating as sometimes it displays the expected output but most of the time ...

Exploring Nodejs and delving into fundamental queries

As I delved into the world of Nodejs, I quickly realized that my knowledge was limited to just being a user. Transitioning to creating my own server posed challenges that were not easily resolved by online tutorials. This led me here seeking guidance to tr ...

Enhance Your Website with Dynamic Navigation Animation

Seeking assistance with animating a navigation bar on and off the screen from the left side. The nav is not animating as expected using the latest version of jquery.min.js. The first step was to animate the nav upon clicking an object. View the current pro ...

Enlarging a JSON structure exported from Clara.IO using Three.js

As a beginner in Three.JS, I have been honing my skills in creating scenes and models. Recently, I imported a washing machine model into my scene and positioned it accordingly. Now, I am trying to scale it up to make it larger, but I am unsure of how to do ...

Best Practices for Converting TypeScript to JavaScript

What is the recommended approach to converting this JavaScript code into TypeScript? JAVASCRIPT: function MyClass() { var self = this, var1 = "abc", var2 = "xyz"; // Public self.method1 = function () { return "somethin ...

Once a session is established within a route, it cannot be accessed or utilized in any other routes within the

I am currently in the process of setting up sessions for my node.js app. To achieve this, I am utilizing modules such as "express", "express-session", and "express-mysql-session" to store the sessions in a database on my server. While my code works perfect ...

Feature to insert a fresh row into SAPUI5 table

I've been attempting to insert new rows into a SAPUI5 table with the click of a button. Despite watching numerous tutorials online, I haven't found one that fits my specific situation. Currently, the JSON data is loaded via a mock server with th ...

Preventing Scope Problems in AngularJS

Spending more than 4 hours trying to figure out why my ng-model directive was not correctly binding with ng-options within my controller was frustrating. The <select> element seemed to be initialized properly, receiving a value from the parent scope, ...

Issues with the last-child selector in CSS being unresponsive

I am having trouble applying styles to the final <p> in a specific div. I would like to achieve this without introducing a new class or ID. Despite attempting to use the last-child selector, I have not been successful in accomplishing my goal. I ha ...

Placing elements in Chrome compared to IE

I'm currently attempting to position elements in two rows using mathematical calculations. One of the elements, thumb_container, is a div that is absolutely positioned. Within this container, I am dynamically loading and appending image thumbnails usi ...

Displaying login error messages using Angular form validation

I'm looking to display an error message of 'Invalid username or password' on the login page whenever a user enters incorrect credentials. Below is my auth.service.ts code: signinUser(email: string, password: string) { firebase.auth(). ...

Is it possible for me to move props object deconstruction into a separate module?

Here is my scenario: I have two React components that share 90% of the same props data, but display different HTML structures. I would like to avoid duplicating variable declarations in both component files. Is there a way to extract the common props des ...

A rightward sliding submenu that appears upon clicking a button

I have a vision of creating an admin control panel for my website, featuring a set of buttons. I envision that when one of the buttons is clicked, the corresponding sub-menu will appear alongside it. For instance, if "My Account" is selected, its sub-menu ...

Exploring the implementation of if statements within jQuery UI Autocomplete

Can conditional statements be used in the response event and the render item implementation? I have two separate JSON files that are accessed through data attributes in #searchbox and .searchbar to retrieve URLs. Since the file objects are different, it se ...

Tips for styling rounded buttons in Svelte Material UI

I am in need of creating a circular button using sveltemateriaui. After checking the examples at , I couldn't find a similar one. However, my attempt to create it using plain CSS resulted in an elliptical shape as shown here: . The only workaround I ...

Currently studying PHP. The classic "Hello world" message is not appearing when using EasyPHP and coding in Notepad++

<html> <!--HTML--> <head><title>a simple test</title></head> <body>a basic test</body> <p>javascript</p> <!--javascript--> <p><script> document.write("hello universe") </sc ...

Is it possible to replace the catch function in JavaScript with a custom function?

Below is the code snippet: function xyz() { try { var a = someexecutions(); handlesuccess(a) } catch (err) { handleerror(err) } } This type of function is repeated numerous times in my codebase and I am looking for a way to improve it. f ...

What does Event.target.id return - the HTML id value or the HTML name value?

HTML Form Example: <form id="form-product-add" style="display: inline;"> <input name="csrf" type="hidden" value="<?= $this->csrf; ?>"> <input type="hidden" name="a ...

Difficulty aligning Material2 icons and title text in CSS styling

I'm encountering a design problem when incorporating material2 icons into my Angular application. Specifically, I have a button that displays both a material2 icon and some text side by side from left to right. Currently, the icons are centered within ...