Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Exit Limesurvey without redirect (close browser tab)

  • JEfromCanada
  • JEfromCanada's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 6 months ago - 1 year 6 months 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 year 6 months 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.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months 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.
Code:
<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.

  • JEfromCanada
  • JEfromCanada's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 6 months ago - 1 year 6 months ago #232149 by JEfromCanada
Replied by JEfromCanada on topic Exit Limesurvey without redirect (close browser tab)
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 year 6 months ago by JEfromCanada. Reason: Gave more information about the rationale for needing to close the tab.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months 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.

  • JEfromCanada
  • JEfromCanada's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 6 months ago #232172 by JEfromCanada
Replied by JEfromCanada on topic Exit Limesurvey without redirect (close browser tab)
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.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months 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.

  • JEfromCanada
  • JEfromCanada's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 6 months ago - 1 year 6 months ago #232175 by JEfromCanada
Replied by JEfromCanada on topic Exit Limesurvey without redirect (close browser tab)
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.
Last edit: 1 year 6 months ago by JEfromCanada.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232176 by Joffm
Here a small example.
php page calls the survey
on the end page there is
Code:
<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.

  • JEfromCanada
  • JEfromCanada's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 6 months ago - 1 year 6 months ago #232183 by JEfromCanada
Replied by JEfromCanada on topic Exit Limesurvey without redirect (close browser tab)
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 year 6 months 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 year 6 months ago #232184 by jelo

and the consensus was that javascript can only close a window that had been opened via a script.
 
When using
Code:
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.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232188 by Joffm
Yes, this small script is in the source code of the end page
Code:
<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
 
Code:
  <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&amp;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

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months 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.

Lime-years ahead

Online-surveys for every purse and purpose