Add simple reusable JS zapi handler

- Factor out logic into a separate JS file to include on each page
- Also, adapt logic to use more reliable method to retrieve url from
reference
Adapt framed pages to use new JS handler