Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Pages created in iframe srcdoc attribute #93

Open
@angloc

Description

@angloc

It is useful sometimes to create the HTML text for an iframe in Javascript and send it to the iframe in the srcdoc attribute. This is most frequently used for self-contained HTML but the document can legitimately access remote resources, and for this purpose HTML provides the element so that relative links in the document are resolved with respect to some external absolute path, rather than with respect to the srcdoc text which would be meaningless.
lab.js requires to know the absolute path to the root of its client document, and captures it in the 'rootpath' variable.
Unfortunately lab.js is not sensitive to this particular use case and finds the rootpath simply by looking at location.href, which doesn't return anything useful for a srcdoc, and in fact causes a Javascript exception.
I haven't worked out a robust fix for this but substituting:
root_page = document.getElementsByTagName("base")[0].href
for
root_page = /^[^?#]*//.exec(location.href)[0]
in line 19 of V2.0.3 source succeeds when the other fails, and vice versa.
Obviously the HTML text you create for your srcdoc has to contain an appropriate <base> element in its <head>,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions