Insert hyperlink, text component, builder, online


I’m testing my experiment online (nothing too serious) just to see how it goes.
At the end of the experiment I would like to attach a hyperlink to a website that participants are supposed to visit to finalize the protocol.
Is this feasible? If yes, how so? If I understood correctly, the text component I inserted in the builder is registered as unicode. So clicking on it ends the routine hence the protocol.

Thanks in advance


OS: windows 7
Psychopy: V 1.84.2

I’ve no way of testing because I do not have a web server to play with. because text is anchored to the textStim you can’t use the inbuilt function that jScript has. In theory this might work though:
In the index.html file ind the -----ending Routine---- for your last routine and add:""); #link to the website in brackets

So on the stoop demo you would have the following:

function thanksRoutineEnd() {
                //------Ending Routine 'thanks'-------
                for (var i = 0; i < thanksComponents.length; ++i) {
                  thisComponent = trialComponents[i];
                  if ("setAutoDraw" in thisComponent) {
      "") #this is where you put the website
                return psychoJS.NEXT;

This will open the site as soon as the experiment ends - in theory… it’s a hack but it should work.



The above was for 1.85.0 html experiments. You can do something similar in experiments using the following:

Create a code component in your last routine and add the following to end of experiment:

import webbrowser"')

This will automatically open your site after the experiment.



Thank you Oliver

Hi Oliver,

I’m encountering an issue with the code. I tried it in the for now for I haven’t done the conversion to html yet.
Here’s the error output:

And here’s my code in the last routine of the protocol:

Any thoughts?

Code components don’t work in PsychoJS yet. Importing webbrowser works fine for me on version 1.84.03 and 1.85.0 standalone so not sure why that’s not working.

In any case - you’ll want to go with the first solution if you’re using HTML i.e."https:\\yoursitehere")



Also spellcheck? :wink:

webbroswer != webbrowser


Thanks! Changed accordingly!

Do you know if there is any way to get a website to open within an experiment? My experiment consists of showing participants lists of words, and then testing them on the words three times. I would like them to play a game online between each of the three tests, and would love if I could get the website to just open up in psychopy. If not, it seems like I have to break the experiment into 4 separate parts.

The only way i can think of would be to set fullscreen to false when your window is created. You’ll lose a bit of precision but will be able to alt-tab to the browser window.

hmmm I’m not exactly sure how to do that. Would it just be a line of code that I put in?

I thought there was a way to do this from builder but the check box makes no difference as of version 1.84. This might have been changed - so maybe try File->Preferences->General and un-ticking ‘Full Screen’ and ticking ‘Allow GUI’

If not, follow these instructions:

In builder click on the paper symbol and find the line of code where the Window is setup. It shouldn’t vary too much between experiments and should be around line 54 - or you can just ctrl-F and search for fullscr. Change this to False and run the experiment from coder mode. If you move back to builder the changes won’t be moved over, and if you click on the paper icon whilst in builder it will overwrite your changes. Once you have finalised your experiment you’ll need to make the changes and run your participants from the coder window (opening the .py file rather than the .psyexp file).


Best wishes,


got a new solution to this - but worth asking @Michael or @jon if it’s legit.

At the end of each experimental routine close the window and redefine the window as fullscr - false.

So in your experimental routine have a code component. In the end routine tab have:

import webbrowser
win = visual.Window(
    size=(1440, 900), fullscr=False, screen=0,
    allowGUI=True, allowStencil=False,
    monitor='testMonitor', color='black', colorSpace='rgb',
    blendMode='avg', useFBO=True,
    units='norm') = win"')

then have a routine called survey or something from which the browser is launched. Include a keyboard component with end routine set to true and a text component named survey_text saying ‘press space to continue’. You’ll also want a code component.

What will happen now is when your experimental condition finishes, win will be replaced with the new non-fullscreen win and the browser will open.

in the code component end routine tab have the following:

win = visual.Window(
    size=(1440, 900), fullscr=True, screen=0,
    allowGUI=False, allowStencil=False,
    monitor='testMonitor', color='black', colorSpace='rgb',
    blendMode='avg', useFBO=True,

#Reinitialise all visual stimuli from your experimental blocks so they know which window to send the data to = win = win

#replace visualStim1 etc with the names of any image, movie or text stim in the next routine.

I’m only bashing this out quickly because I have to be somewhere but have a play and see what happens. This way you get the best of both worlds.



Hi @Oli, it’s generally not a great idea to be closing and re-creating the win Window instance that Builder initialises. That could break all sorts of things (for example, maybe its list of auto-drawing stimuli). You’ve already noted that all of the existing visual stimuli would need to be linked back to the new window instance, and that could easily go wrong. The main PsychoPy window instance doesn’t need to be destroyed: it can simply be minimised, and then you could open the web browser as above. The PsychoPy window could then be maximised and reactivated again, as per this thread:

Having said that though, I’m not sure how PsychoPy would know when to do the maximisation step (i.e. how it would learn when the web browser window has finished/been closed).

Hi @Oli, while searching the forum I came across your solution about opening a website after the experiment has ended. I tried to run an experiment with your code online on Pavlovia, but the experiment gets stuck right at the beginning (during “initializing the experiment…”). When trying the experiment without your code component, it works just fine and I don’t receive any errors. Do you know what could cause this error and how to fix it?