Click on the link in the modal to either download the image or view a larger version

Struggling to create a photo gallery similar to Google Photos because of large image sizes - around 15mb - causing slow loading for users with poor connections.

Currently using a placeholder image while waiting for the full-size image to load, but encountering issues with right-clicking and viewing the full-size image which links to the small image file.

My main goal is to add a link within the modal to direct users to the full-size image.

https://jsfiddle.net/mikemaer/ghc9o1v6/10/

`function onClick(element) {
        document.getElementById("img01").src = element.src;
        document.getElementById("modal01").style.display = "block";
    }

    (() => {
        'use strict';
        // Page is loaded
        const objects = document.getElementsByClassName('asyncImage');
        Array.from(objects).map((item) => {
            // Start loading image
            const img = new Image();
            img.src = item.dataset.src;
            // Once image is loaded replace the src of the HTML element
            img.onload = () => {
                item.classList.remove('asyncImage');
                return item.nodeName === 'IMG' ?
                    item.src = item.dataset.src :
                    item.style.thumbnail = `url(${item.dataset.src})`;
            };
        });
    })();`

Example used a random image without the placeholder image.

Only relevant post found was this --- Modal image with download link and the only suggested solution was to implement PHP.

If anyone has advice for a beginner like me, it would be greatly appreciated.

Answer №1

This could be the only solution available for this scenario. If you come across a better alternative, feel free to utilize it. Make sure to double-check everything here.

<img src="https://edmullen.net/test/rc.jpg" data-src="img/canon (1).JPG" onclick="onClick(this)" class="mm-hover-opacity asyncImage" oncontextmenu="window.open('https://edmullen.net/test/rc.jpg', '_blank')">

You have the option to substitute the URL of the high-quality image file with

oncontextmenu="window.open('https://edmullen.net/test/rc.jpg', '_blank')

By this, I mean

oncontextmenu="window.open('img/canon (1).JPG', '_blank')

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

Having trouble accessing Kotlin JS from JavaScript

I'm currently experiencing an issue where I am unable to call any Kotlin JS function and receiving an error stating that 'something' is not defined. Initially, I attempted compiling the project with Gradle but found success after following ...

Having trouble getting a Mocha test to display two decimal places in Javascript? Both Big and Decimal libraries are causing issues

After encountering an error with the Big library, I decided to switch to Decimal. First, I ran npm install Decimal Then, I added the following code: const Decimal = require('decimal'); Even after following the examples, my comparison returned { ...

Is there a way to send an array of objects to my Express / SQL Server in react?

I am currently facing a challenge with passing an array of objects to my back end (SQL Server). Below is the specific array of objects: console.info(results) Here is the array of objects named results: [0] [ [0] { [0] answer: 'bmbm,nn', [ ...

Is there a way to assess Python code within a document's context using JavaScript in JupyterLab?

When using Jupyter Notebooks, I can create a cell with the following JavaScript code: %%javascript IPython.notebook.kernel.execute('x = 42') After executing this code, in another cell containing Python code, the variable x will be bound to 42 a ...

Struggling to employ JavaScript events when submitting a form to verify the fields

My goal is to create a form with fields that have real-time validation using JavaScript. I have achieved this by utilizing Java events in the following way: Text field onkeyup: This event sends a request to check for errors in the field every time a key ...

Transmitting a Custom JS Object via Vue Router

Stuck! I’ve been hitting my head against the wall for hours trying to figure this out... Technologies Utilized: Vue (v3.0.0) Vue-Router (v4.0.0-0) Bootstrap (v5.1.1) The Objective: I have two pages (Home.vue, MetaUpdate.vue) and one component (Docum ...

The SetCookie header was not properly stored within the system

Currently, I am developing a web application using node/express.js for the backend API and Vue.js for the frontend. Regarding authentication, I am implementing JWT and sending the value through an HttpOnly cookie. However, despite seeing the "Set-Cookie" ...

Angular 2 Error: When used in strict mode functions or arguments objects, the properties 'caller', 'callee', and 'arguments' may cause a TypeError

I'm facing an issue with Angular 2 that seems to be a common problem, but I haven't been able to find a solution yet. I've created a service that is called from another Component, which works fine. The problem arises when I try to make an h ...

PhoneGap iOS application storing outdated information

My Phonegap 2.1 app running on iOS 6, with jQuery 1.7.2 and JQMobile 1.1.1 libraries, is experiencing an issue where old data from ajax responses gets cached if the app is unused for a few days. The only way to resolve this issue is by reinstalling the a ...

The moduleId in "Ng2SliderComponent" must be a valid string

My angularcli.json configuration looks like this: "scripts": [ "../node_modules/ng2-slider-component/ng2-slider.component.js", "../node_modules/ng2-slideable-directive/slideable.directive.js", "../node_modules/ng2-styled-directiv ...

Exploring the possibilities with New Relic and React

I am working with a react-router layout which currently contains a string that includes the New Relic javascript snippet. Now, I want to utilize the Browser Agent and set a custom attribute. newrelic.setCustomAttribute(name, value) The global variable n ...

Reactjs encountering issues loading css file

Currently, I am working on a project in Reactjs with Nextjs. To add CSS to my project, I have stored my CSS files in the 'styles' folder. In order to include them, I created a file called '_document.js' and implemented the following cod ...

Generating step definitions files automatically in cucumber javascript - How is it done?

Is there a way to automatically create step definition files from feature files? I came across a solution for .Net - the plugin called specflow for Visual Studio (check out the "Generating Step Definitions" section here). Is there something similar avail ...

Steer clear of 405 errors by implementing AJAX in combination with Flask and JINJA templ

Hey there, I'm fairly new to backend work so please bear with me. I've been doing some research but haven't found the answer yet. Currently, I'm working on an application that fetches search results from a 3rd party API. I'm tryi ...

The error message "Create controller with service — Get... is not a function" indicates that

Within my ASP.NET Boilerplate project, the following code snippet is present: (function () { appModule.controller('augustinum.views.kostenstelle.index', [ '$scope', '$uibModal', 'abp.services.app.kostenstelle ...

Error encountered while executing a join query in Node.js

My stack includes express.js, sequelize, and mysql Database Structure A : { id: 1, name: ... } B : { A_id: 1, name: name1 }, { A_id: 1, name: name2 } A Model (models/A.js) A.association = models => { A.hasMany(models.B, { foreignKey: 'A_id&ap ...

Updating Values in Nested Forms with Angular Reactive Form

I have been grappling with a form setup that looks something like this: itemEntities: [ {customisable: [{food: {..}, quantity: 1}, {food: {..}, quantity: 5}]}, {customisable: [{food: {..}, quantity: 0}]}, ] My challenge lies in trying to u ...

The functionality of Jquery draggable is not functioning

  On one of my websites, I have a div that contains an image that is wider than the div itself. To view the entire image, it needs to be moved using the mouse. However, I have encountered a problem when moving the image to the right and in other directi ...

Exploring the potentials of AngularJs Datatables Promise and the ignited power of Ignited

I am currently facing an issue with populating a datatable in AngularJS. DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.n ...

Issue with SVG on tainted canvas causes IE security error when using toDataURL

In my Angular JS directive, I have implemented a feature to export SVGs to PNG. While this functionality works seamlessly in most browsers, it encounters a security error in IE. Despite my numerous attempts to troubleshoot the issue, I have been unable to ...