I am using Limesurvey to create a customer survey. As I want to embed the survey at my company's homepage, I am using an iframe to make that happen. This ensures that I have my official header and footer available and I don't have to rebuild that elements in Limesurvey.
Limesurvey offers a possibility to redirect to another page after somebody has completed the survey (e.g. a thank you page). As I am embedding Limesurvey, I cannot redirect to my offical thank you site from my company's homepage as I would have double header and double footer.
What I have thought of, is to redirect to a dummy site. From the parent site, I want to check for that event and trigger my redirection to my thank you site.
I have no idea how to do that in Javascript. How do I define an event listener to check if a specific site has been loaded within the iframe and then fire my redirection in the parent.
Thanks a lot!
You can inspect the URL in the IFrame using <element>.documentWindow.location.href
if it is on the same domain:
e.g if your iframe
had id 'frame'
document.getElementById('frame').documentWindow.location.href
However, You can't inspect the URL inside an IFrame if the IFrame is on a different domain, this is due to a security mechanism in modern browsers.
If you are not in the same page it will raise an exception:
Error: Permission denied to get property Location.href
See this SO answer for more detail also as noted here the property is named differently in chrome: documentWindow is called contentDocument in Chrome
LimeSurvey and my parent page are on the same top-level domain. So no issue from there. How can I do it?
@Sven I've updated hope that helps
Your link helped me to find the following working proof-of-concept: stackoverflow.com/questions/2429045/…. Thanks a lot! Redirect is now recognized :-)