Skip to content

Truly independent web browser

1.6 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<map name="first">
    <area id="area-in-first" shape="rect" coords="0,0,100,100" href="#first" alt="first">
</map>
<map name="second">
    <area id="area-in-second" shape="rect" coords="0,0,100,100" href="#second" alt="second">
</map>
<img id="image" usemap="#first" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==" width="100" height="100" alt="image map">
<script>
    test(() => {
        const image = document.getElementById("image");
        const imageRect = image.getBoundingClientRect();

        document.addEventListener("click", event => {
            event.preventDefault();
        });

        function clickTargetAt(x, y) {
            let target;
            document.addEventListener("click", event => { target = event.target; }, { once: true });
            internals.click(imageRect.x + x, imageRect.y + y);
            return target;
        }

        println(`initial association targets the first map: ${clickTargetAt(50, 50).id === "area-in-first"}`);

        image.setAttribute("usemap", "#second");
        println(`changing usemap targets the second map: ${clickTargetAt(50, 50).id === "area-in-second"}`);

        image.setAttribute("usemap", "#renamed");
        println(`unmatched usemap targets the image: ${clickTargetAt(50, 50).id === "image"}`);

        document.querySelector("map[name=second]").setAttribute("name", "renamed");
        println(`renaming a map re-associates the image: ${clickTargetAt(50, 50).id === "area-in-second"}`);
    });
</script>