Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Update image source form one html page to another

I'm creating a scoreboard in html that is controlled by another html page. I work with messages like proposed in the answer of my previous post (display text on a child window in javascript) It is working really good and I can update text. Now I'm trying to change the source of an image.

main.js

const setFaute1 = (faute1) => {
    afffaute1.innerHTML = faute1;
    switch (faute1) {
        case 1:
            faute11.src = './images/FillFault.png';
            break;
        case 2:
            faute12.src = './images/FillFault.png';
            break;
        case 3:
            faute13.src = './images/FillFault.png';
            break;
        case 0:
            faute11.src = './images/EmptyFault.png';
            faute12.src = './images/EmptyFault.png';
            faute13.src = './images/EmptyFault.png';
            break;
    }
    bc.onmessage = (messageEvent) => {
        switch (messageEvent.data) {
            case 'update_mot':
                setMot(localStorage.getItem('mot'));
                break;
            case 'update_equipe1':
                setEquipe1(localStorage.getItem('equipe1'));
                break;
            case 'update_equipe2':
                setEquipe2(localStorage.getItem('equipe2'));
                break;
            case 'update_score1':
                setScore1(localStorage.getItem('score1'));
                break;
            case 'update_score2':
                setScore2(localStorage.getItem('score2'));
                break;
            case 'update_faute1':
                setFaute1(localStorage.getItem('faute1'));
                break;
            case 'update_faute2':
                setFaute2(localStorage.getItem('faute2'));
                break;
            default:
        }
    };
    btnfaute1.onclick = (e) => {
        var value = parseInt(afffaute1.innerHTML, 10);
        if (value < 3) {
            value++;
        } else {
            value = 0;
        }
        localStorage.setItem('faute1', value);
        afffaute1.innerHTML = value;
        setFaute1(value);
        bc.postMessage('update_faute1');
    };
};

It displays correctly on the page where the button is but not on the second page. The text field updates correctly.

I don't understand why. Can someone help me?

Full code : https://gitlab.com/roger.julien/tableau-affichage-impro/-/tree/fautes

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I found the solution myself. The localstorage stores string. And my case was comparing integer. I just had to convert the string to an integer and it works.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!