Exit Limesurvey without redirect (close browser tab)

More
1 week 5 days ago - 1 week 5 days ago #232133 by JEfromCanada
Please help us help you and fill where relevant:
Your LimeSurvey version: most recent 3.x LTS and most recent 5.x (as of Sept 20, 2022)
Own server or LimeSurvey hosting: self-hosted on shared hosting server on A2 Hosting
Survey theme/template: fruity - no customizations
==================
(Write here your question/remark)

I am using both the current 3.x LTS (installed latest download on September 20, 2022 as an update to my 3.x version) as well as a newly installed 5.x version (also downloaded and installed September 20, 2022).

My publicly accessible survey is linked from a website which has a page with multiple possible surveys.  When a survey is selected, the website activates the survey in a separate browser tab.  When the survey is complete, I simply want LimeSurvey to close down (i.e. abort and close the tab) so the original webpage is now showing.  If I use the END-URL feature, I end up loading multiple copies of my website, which is wasteful of resources and confusing for the user.

How do I simply CLOSE Limesurvey after a submission?
Last edit: 1 week 5 days ago by JEfromCanada. Reason: Answers to software/hardware configuration were not at the top of the post, but rather inside the post.

Please Log in to join the conversation.

More
1 week 5 days ago #232141 by Joffm
Hi,
I found this on Stackoverflow:
onClick="javascript:window.close('','_parent','');"

So you may place this on the thank you page:
Additionally here is the timeout function in case you want to display a "Thank you" message. Otherwise remove it.
<input id="mybutton" onclick="javascript:window.close('','_parent','');" type="hidden" /> 
 
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
    setTimeout(function () {
      $('#mybutton').trigger('click');
    }, 5000);
});
</script>

There may be other solution, but it works.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 5 days ago - 1 week 5 days ago #232149 by JEfromCanada
Yeah, I saw several posts on StackOverflow in regards to javascript closing a tab, and the consensus was that javascript can only close a window that had been opened via a script. I will definitely try this, but after what I read, I was discouraged.

EDIT:  My scenario is actually quite a bit more complex.  I have a site that, for whatever reason, will not allow Apple devices to access the LimeSurvey (no idea what's causing this).  The only workaround I could think of that would still "appear" to work was to create an iframe on site "A" (the problem site), which references the LimeSurvey that's now been moved to a different domain and is now running on site "B".  So, when the survey ends, I want site B to close the tab that's displaying the survey, and then (hopefully), the users of site "A" will again see the "landing page" from which they activated the survey in the first place.
Last edit: 1 week 5 days ago by JEfromCanada. Reason: Gave more information about the rationale for needing to close the tab.

Please Log in to join the conversation.

More
1 week 4 days ago #232166 by holch

which is wasteful of resources and confusing for the user.


To be honest, I don't see how this would be confusing to users, and less so why this would be "wasteful of resources".

From a user point of view, I don't want ANYONE to close my browser tabs or windows but me. The browser is mine. I decide when I close a window.

and the consensus was that javascript can only close a window that had been opened via a script.


That is also what I know.

I would instead of using the end url just use the end message and tell respondents that they can now close the tab. Or you don't open the survey in a new tab in the first place and then use the end url to redirect them to the website you want them to see after the survey. All happens in just one tab, no "resources wasted", no confusion.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

More
1 week 4 days ago #232172 by JEfromCanada
I totally agree with you, holch, about just starting the survey from the same Window. But the software I'm using to generate the landing page seems to have a bug in it... despite me using the [target="_self"] directive in the a-tag, the browser is still opening the survey in a new tab. I've opened a ticket with their support department to see if there is a solution or workaround.

Please Log in to join the conversation.

More
1 week 4 days ago #232173 by holch
The behaviour to open in the same tab / page / iframe is the default. In theory you shouldn't even have to use target="_self". Really strange.

Well, it's Apple...

You say it is on Apple devices. But does this mean it happens with any browser on Apple devices or is it rather a Safari specific problem?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

More
1 week 4 days ago - 1 week 4 days ago #232175 by JEfromCanada
Happens on Safari, Chrome, Firefox and Opera. I have several people who have sent me screen captures of HTML code dumps, where the code is displayed on the screen instead of running the code. It's similar to what happens if you try to run a PHP script on a server that doesn't have a PHP handler installed. But of course, that's not the case, since all non-apple devices are able to work properly.

EDIT:  Also happens on multiple iphone models and ipads (even seen it on an iMac).  BUT, I've also seen certain iphones work!  I just can't verify the age or iOS version of those that are working - because when it works, I don't hear about it.
Attachments:
Last edit: 1 week 4 days ago by JEfromCanada.

Please Log in to join the conversation.

More
1 week 4 days ago #232176 by Joffm
Here a small example.
php page calls the survey
on the end page there is
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
    setTimeout(function () {
         window.open('','_parent',''); 
         window.close();
    }, 5000);
});
</script>

Video:

 


Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: JEfromCanada

Please Log in to join the conversation.

More
1 week 4 days ago - 1 week 4 days ago #232183 by JEfromCanada
Love it. Thank you.

Sorry, one more clarification.  Normally, I use the option to display the End Message and then manually wait for the user to click the link to proceed somewhere.  Since there was no user interaction, I'm assuming you had chosen the automatic end to the survey (as opposed to waiting for a click).  So, where is the javascript code being entered?  I'm not sure I've ever seen a place where javascript is prompted for.  Does it live inside the End Message field, and simply get executed when the automatic exit from survey is triggered?
Last edit: 1 week 4 days ago by JEfromCanada. Reason: Adding a request for clarification of where the javascript code should be entered.

Please Log in to join the conversation.

More
1 week 4 days ago #232184 by jelo

and the consensus was that javascript can only close a window that had been opened via a script.
 
When using
usetarget="_blank"
in the link, you should be able to close the tab /window too.

h

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

More
1 week 4 days ago #232188 by Joffm
Yes, this small script is in the source code of the end page
<span style="font-size:20px;font-weight:bold">This TAB will be closed in 5 seconds</span> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){
    setTimeout(function () {
         window.open('','_parent',''); 
         window.close();
    }, 5000);
});
</script>
As said before, you may remove the timeout function.
I only inserted it to show the effect.

And this is the php page that calls the survey
 
  <body>
    <div class="container">
      <div class="jumbotron">
        <h1>Hello, world!</h1>
        <h2>A simple php page</h2>
        <a href="https://www.myserver.de/limesurvey/index.php/846238?lang=en&newtest=Y" target="_blank" class="button">Start the survey</a>
      </div>
    </div>
  </body>

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in to join the conversation.

More
1 week 4 days ago #232189 by Joffm
Sorry, the screenshot is misplaced.
Should be at the top.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 4 days ago - 1 week 4 days ago #232190 by JEfromCanada
Joffm, you've been really helpful with the code snippet, but my 70 year old brain is missing one piece. I have an HTML page that is the launch pad for my surveys (there are 24 surveys - each with 1 question - displayed on the landing page). What I think you're saying is that, in addition to my HTML launch page, I need to create a SEPARATE html document that will contain the javascript code above. And I will need to execute WITHIN EACH SURVEY an automatic exit to the URL of this second html document.

Since my launch page sits on a different domain from the surveys themselves, does the javascript code need to be in a file on the server where the surveys are, or does it need to be on the same server as the launch page, or does it not matter because I need to specify a complete URL of the exit page within the survey, so it can be located anywhere?

Now, if I'm wrong and there is NOT a separate document to hold the javascript code, then my original question exists - where within the survey interface does the javascript get entered? Is it in the box where the "Exit Message" would normally be typed? That's the part that confused me before, since I wasn't aware that executable content could be placed in that area.

EDIT:  I think I just answered my own question.  Looking more carefully at the editor box where the Javascript is written, it appears to look like the input area of the End Message, so now I'm thinking that "Endnachricht" is the German equivalent of "End Message".
Last edit: 1 week 4 days ago by JEfromCanada. Reason: I finally get it! That screen image of the javascript code INSIDE THE CODE EDITOR finally clued me in where it is located.

Please Log in to join the conversation.

More
1 week 4 days ago #232192 by JEfromCanada
I see that the HTML file that calls the survey opens up a new window with the target="_blank" directive, and I'm assuming that's why in the closing code, you are trying to open the "_parent" window.

If, in my scenario, I am opening up the survey with a target="_self" directive, does that mean I need to use the "_self" directive in the Javascript, or does it mean I may not be able to use this method at all unless I launch the survey into a different browser tab?

Please Log in to join the conversation.

More
1 week 4 days ago #232198 by jelo

 may not be able to use this method at all unless I launch the survey into a different browser tab?
 
The browser behaviour has changed over the years, because security has been tighten everywhere.And it will go on like this.
In the old days the survey was opened via JavaScript fullscreen to ensure focus of the proband.That was misused by advertising, so that the popupcontrol was introduced.

Currently I think the following is still working with uptodate browsers.
If you open a tab/window via _blank (which can be done via a simple link without Javascript involved), you can close that tab via JavaScript.
If you open a tab/window via JavaScript, you can close it via JavaScript.

Browser behaviour changes a lot. E.g. when opening a new tab via _blank, is the browser changing the focus to the new tab or not. Where is the browser adding the tab in the tabbar? At the end or directly behind the parent page? That has an big impact on the survey flow and cannot be controlled by the webpage.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now