# Insert hyperlink, text component, builder, online

**URL:** <https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079>\
**Category:** Online experiments\
**Created:** [March 8, 2017, 3:51pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079 "2017-03-08T15:51:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatthieuLH](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@MatthieuLH](https://discourse.psychopy.org/u/MatthieuLH)\
**Post date:** [March 8, 2017, 3:51pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/1 "2017-03-08T15:51:34Z")

</div>

Hi,

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

Matthieu

OS: windows 7  
Psychopy: V 1.84.2

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [March 8, 2017, 4:37pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/2 "2017-03-08T16:37:13Z")

</div>

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 str.link 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:

```auto
window.open("https://www.yourwebsitehere.com"); #link to the website in brackets

```

So on the stoop demo you would have the following:

```auto
function thanksRoutineEnd() {
                //------Ending Routine 'thanks'-------
                for (var i = 0; i < thanksComponents.length; ++i) {
                  thisComponent = trialComponents[i];
                  if ("setAutoDraw" in thisComponent) {
                    thisComponent.setAutoDraw(false);
                  }
                }
                window.open("https://www.psychopy.org") #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.

BW

Oli

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [March 8, 2017, 4:41pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/3 "2017-03-08T16:41:50Z")

</div>

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:

```auto
import webbrowser

webbrowser.open("https://www.yourwebsitehere.com')

```

This will automatically open your site after the experiment.

BW

Oli

---

<div class="post-metadata">

**Author:** ![MatthieuLH](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@MatthieuLH](https://discourse.psychopy.org/u/MatthieuLH)\
**Post date:** [March 9, 2017, 8:42am UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/4 "2017-03-09T08:42:44Z")

</div>

Perfect  
Thank you Oliver

---

<div class="post-metadata">

**Author:** ![MatthieuLH](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@MatthieuLH](https://discourse.psychopy.org/u/MatthieuLH)\
**Post date:** [March 10, 2017, 8:55am UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/5 "2017-03-10T08:55:03Z")

</div>

Hi Oliver,

I’m encountering an issue with the code. I tried it in the expermient.py for now for I haven’t done the conversion to html yet.  
Here’s the error output:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/2X/0/026e64fb24cf7ac9a1c62fda2b1912064d5d1258.JPG)

And here’s my code in the last routine of the protocol:  
 ![](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/2X/2/24ad133a2249e79d49d7b6dab7b7f6c401f114c4.JPG)

Any thoughts?

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [March 10, 2017, 10:37am UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/6 "2017-03-10T10:37:54Z")

</div>

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.

```auto
window.open("https:\\yoursitehere")

```

BW

Oli

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [March 11, 2017, 10:37pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/7 "2017-03-11T22:37:33Z")

</div>

Also spellcheck? 😉

webbroswer != webbrowser

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [March 11, 2017, 10:43pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/8 "2017-03-11T22:43:44Z")

</div>

Thanks! Changed accordingly!

---

<div class="post-metadata">

**Author:** ![willi4cm](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@willi4cm](https://discourse.psychopy.org/u/willi4cm)\
**Post date:** [September 25, 2017, 4:22pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/9 "2017-09-25T16:22:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [September 25, 2017, 8:30pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/10 "2017-09-25T20:30:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![willi4cm](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@willi4cm](https://discourse.psychopy.org/u/willi4cm)\
**Post date:** [September 26, 2017, 3:32pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/11 "2017-09-26T15:32:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [October 1, 2017, 2:52pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/12 "2017-10-01T14:52:19Z")

</div>

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).

![54](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/f/7f75c30eb1f8a92efc1f9dcdd731f97d58c8d320.png)

 ![16](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/7/478525905acc16ad48bffc84df6533fbb10322e0.png)

Best wishes,

Oli

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [October 1, 2017, 3:29pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/13 "2017-10-01T15:29:18Z")

</div>

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:

```auto
import webbrowser
win.close()
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')

survey_text.win = win
webbrowser.open("https://www.yourwebsitehere.com')

```

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:

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

#Reinitialise all visual stimuli from your experimental blocks so they know which window to send the data to
visualStim1.win = win
visualStim2.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.

BW

Oli

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [October 1, 2017, 7:50pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/14 "2017-10-01T19:50:43Z")

</div>

> [@Oli](#):
>
> win.close()  
> win = visual.Window(etc…

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:

> [@Bug: User-defined GUI does not display in full screen on Mac OSX](https://discourse.psychopy.org/t/bug-user-defined-gui-does-not-display-in-full-screen-on-mac-osx/2214):
>
> I have an experiment that requires a secondary GUI to input information after the inital “participant/session” GUI. I’m running this on a Mac OSX El Capitan (10.11.6). If I uncheck “full screen” in the settings, it displays fine. If it’s full screen, it’s clear that the gui is being displayed behind the window. A small example is below. By simply changing fullscr to True or False you can see that it won’t display. I haven’t had a chance to test on other platforms. I suppose the alternative is t…

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).

---

<div class="post-metadata">

**Author:** ![Mel499](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/mel499/32/6581_2.png) [@Mel499](https://discourse.psychopy.org/u/Mel499)\
**Post date:** [April 21, 2020, 12:11pm UTC](https://discourse.psychopy.org/t/insert-hyperlink-text-component-builder-online/2079/15 "2020-04-21T12:11:39Z")

</div>

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?
