弒天下
2023-06-15 10:25:20
我有兩個 HTML 頁面;main.html和result.html。主要.html: <img id="preview" src="" alt=""> <button id="done" type="button">done</button>結(jié)果.html: <img id="search" src="" alt="">在main頁面中,我上傳了一張圖片,預(yù)覽顯示在previewof中main。然后我使用 cropper js 模塊裁剪了這張圖片。crop.js:const done = document.getElementById('done');const imgcropped = document.getElementById('img-cropped');done.addEventListener('click', (e) => { imgcropped.src = cropper.getCroppedCanvas().toDataURL();})我想去imgcropped.src里面search.src。result我怎樣才能得到main圖像result?
1 回答

UYOU
TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個贊
您可以使用localStorage.
在 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);
});
在 result.html 中:
var searchImg = document.getElementById("search")
if(window.localStorage.getItem("imgcropped") !== null){
searchImg.src = window.localStorage.getItem("imgcropped");
}
添加回答
舉報
0/150
提交
取消