Skip to content

Unable to control my embedded Sozi form outside the <iframe> as described in the documentation #680

@SirClickALot

Description

@SirClickALot

Summary of your problem or feature request

I cannot seem to control my embedded Sozi form outside the <iframe> because Javascript cannot 'find' the 'player'...

I am Sozi 23.07.25-1690311612

I use a drawing program called Xara Designer Pro+ but I include that info here purely for compliance as there is no problem with SVG itself.

Steps to reproduce the problem

Understanding the guidance on embedding

I have read and understood the guidance (https://sozi.baierouge.fr/pages/tutorial-embedding.html) on communicating with a Sozi when it is embedded in an an IFRAME and below is the <iframe> that I am using to embed my Sozi...

<iframe id="sozi-frame"src="https://sirclickalot.co.uk/assets/books/gcse-computer-science-plus/chapters/computer-systems/topics/introduction-to-computer-systems/journeys/the-basic-computer-system-process-breakdown/braille-to-english-landscape.sozi.html" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>

This all seems to work exactly as expected.

Why have I given the <iframe> an ID?

You will notice that I have given the <iframe> an ID of 'sozi-frame'.
I initially tried to target the iframe exactly as described in the guidance but got no joy there either so rather than simply target the 'first' <iframe> in my out Javascript, I chose to be more specific by using...

var sozi_frame = document.getElementById("sozi-frame");

I can 'see' this <iframe> in my Javascript perfectly fine - the ULR is public so anyone can try it out.

Here is the full tweaked version of my javascript - I am not interested in the Sozi frame titles so mine is slightly cut down from the guidance example...

<script>
    var sozi_frame = document.getElementById("sozi-frame");
    var sozi_player = sozi_frame.contentWindow.sozi.player;
    alert(sozi_player);

    var btnPrev   = document.getElementById("btn-prev");
    var btnNext   = document.getElementById("btn-next");

    btnPrev.addEventListener("click", function () {
        player.moveToPrevious();
    }, false);

    btnNext.addEventListener("click", function () {
        player.moveToNext();
    }, false);    
</script>

NOTE the crude but illustrative alert() on the third line - we never reach this point because the value of sozi_player is null.

The Javascript console reports...

Uncaught TypeError: Cannot read properties of undefined (reading 'player')

I am at a loss here, can anyone please help me to see what I'm missing?

Why does my sozi_player frame appear to be missing its .player?

Resources for anyone who can help

HERE is the working HTML that tries to target the 'player' using the grey btnNext and btnPrev at the bottom right corner.

HERE is an archive of my Sozi for reference.

Thanks all, getting this solved will open the doors to me using and promoting Sozi widely in our open source education project so I would be very grateful for any advice given.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions