我有两个 HTML 页面;main.html和result.html。主要.html: <img id="preview" src="" alt=""> <button id="done" type="button">done</button>结果.html: <img id="search" src="" alt="">在main页面中,我上传了一张图片,预览显示在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贡献1878条经验 获得超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
提交
取消