Wie bekomme ich mit JavaScript ein Bild src auf einer anderen Seite? [Duplikat]
Nov 23 2020
Ich habe zwei HTML-Seiten; main.html
und result.html
.
main.html:
<img id="preview" src="" alt="">
<button id="done" type="button">done</button>
result.html:
<img id="search" src="" alt="">
Auf der main
Seite lade ich ein Bild hoch und die Vorschau wird in preview
von angezeigt main
. Und dann habe ich dieses Bild mit dem Cropper JS-Modul zugeschnitten.
crop.js:
const done = document.getElementById('done');
const imgcropped = document.getElementById('img-cropped');
done.addEventListener('click', (e) => {
imgcropped.src = cropper.getCroppedCanvas().toDataURL();
})
Ich möchte bekommen , imgcropped.src
um die search.src
in result
. Wie kann ich das main
Bild zum bekommen result
?
Antworten
1 MerliMejia Nov 23 2020 at 21:42
Sie können das mit tun localStorage
.
In main.html:
const done = document.getElementById('done');
const imgcropped = document.getElementById('img-cropped');
done.addEventListener('click', (e) => {
var newSrc = cropper.getCroppedCanvas().toDataURL();
imgcropped.src = newSrc;
window.localStorage.setItem("imgcropped", newSrc);
});
Und in result.html:
var searchImg = document.getElementById("search")
if(window.localStorage.getItem("imgcropped") !== null){
searchImg.src = window.localStorage.getItem("imgcropped");
}