предзагрузка изображения в js | image preload in js - Forum

Forum Navigation
You need to log in to create posts and topics.

предзагрузка изображения в js | image preload in js

Я напишу qrcode генератор с поддержкой utf8, сам генератор работает, все отлично.
Но я хотел добавить логотипы и столкнулся с проблемой, я не могу создать предзагрузку изображения логотипа.
Изображение логотипа в формате base64. Я перепробовал уже много вариантов, но ничего не получается, функции просто не ожидают загрузку
Да же в простом варианте загрузка изображения не ожидается.

I will write a qrcode generator with utf8 support, the generator itself works, everything is fine.
But I wanted to add logos and ran into a problem, I can't create a logo image preload.
Logo image in base64 format. I have already tried many options, but nothing works, the functions simply do not expect loading
Even in the simple version, image loading is not expected.

Не могу разместить код примера.  Мне нужно изображение в base64 загрузить в img и после вставить img в qrcode
I can't post the example code. I need to upload a base64 image to img and then insert the img into qrcode

Я нашел причину, await работает только в асинхронной функции, а асинхронная функция не ожидает, а продолжает работу. Поэтому нужно использовать image./on/load, и не возвращать ответ, а передавать его в подпрограмму.

I found the reason, await works only in async function, and async function does not wait, but continues to work. So you need to use image./on/load, and not return the response, but pass it to the subroutine.

у форума какие-то проблемы с защитой, я не могу написать код
the forum has some security issues, i can't write code

luishp and Vadim have reacted to this post.
luishpVadim