Get URL from iframe?

I have a Hype doc living in an iframe inside various HTML pages.

Is there a simple way to get the URL or title of the HTML page from within the Hype document? (Everything I’ve tried via Javascript returns the attributes of the iframe.)

My Hype file and resources live in a separate directory from the HTML pages.

The reason I want to do this is because the Hype document is navigation. By reading the URL or title, I can set the “you are here” part correctly.

I’m a newbie and any help is appreciated. Thx.

Basic approach, bulletproof

That should get you started (untested, I am on the iPhone)

<iframe href="hypeframe.html#your-identifier"></iframe>

In Hype you can then

var identifier = window.location.hash;
// do something with that information like trigger a custom behavior etc.

Extended approach, sandbox restrictions may apply

If you need more data. You could us a JSON string as a hash or look into the frameElement and use data attributes on the frame and retrieve them from window.frameElement, see

2 Likes

If you only want the URL calling the iFrame also check out

4 Likes

This was helpful. Thank you for the response.