Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

[open] How to insert HTML link to a webpage?

esuahnilesuahnil Posts: 5
edited October 2013 in OpenSesame

Hi,

I'm using a Form Text Render to display a goodbye message at the end of an experiment. I want to insert an HTML link that, when clicked, opens the site with a web browser (i.e., I want to direct participants to a particular website after completing the experiment in OpenSesame). How do I go about doing this? Thanks very much!

Comments

  • sebastiaansebastiaan Posts: 2,813
    edited October 2013

    Hyperlinks are not supported in OpenSesame. But you can approximate this functionality by adding a button to your form, and use an inline_script item to open a specific URL in an external browser when this button is clicked.

    For example, if you create a form_base with the following script, you will see two buttons:

    # Form_base script
    set rows "1;1"
    set cols "1"
    widget 0 0 1 1 button var="open_cogsci" text="Open http://www.cogsci.nl"
    widget 1 0 1 1 button text="Do nothing"
    

    If you click the button labeled 'Open http://www.cogsci.nl/', the variable open_cogsci will be set to 'yes', and you can use this to launch a webbrowser in an inline_script placed after the form_base:

    # Inline_script
    import webbrowser
    if self.get('open_cogsci') == 'yes':
        webbrowser.open('http://www.cogsci.nl/')
    

    Note that the resulting behavior may be a bit odd on some systems, because the OpenSesame window will loose focus, which is not what OpenSesame is designed for. But it might do the job for you.

    Cheers!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • esuahnilesuahnil Posts: 5
    edited 8:01PM

    I'll try it and see whether it works. Thanks Sebastiaan!

  • erwinwirneerwinwirne Posts: 18

    Dear all

    I would also like to add a link in OpenSesame which directs the participants to an online questionnaire (on Unipark). Is this still the only possibility to do so or is there an easier way by now?
    I would like to give the participants brief instructions and then ask them to click on the link in order for them to get redirected to the online questionnaire.

    Thanks in advance for your help!

  • sebastiaansebastiaan Posts: 2,813

    Yes, this is still the only way. But it does what you want to do, right?

    Thanked by 1erwinwirne

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • erwinwirneerwinwirne Posts: 18

    Dear sebastiaan

    Sorry for my late answer! Yes, it does what I want it to do. I modified your version a bit. Instead of a form base I used a sketchpad and a response keyboard. I adopted your inline script and changed the answer:

    import webbrowser
    if self.get('open_cogsci') == 'space': #particpants have to press the spacebar to continue
        webbrowser.open('http://www.cogsci.nl/')

    This works just fine (thanks for the code)! I have just one problem: when I run the experiment in the fullscreen mode and I press the spacebar, the experiment closes but the website opens "in the background" - meaning that the link doesn't pop up, instead the OpenSesame menu is visible (the link opens but I have to actively click on the webbrowser to see the link). Does this make sense?
    Is there a way to modify the code so the link pops up automatically (when I use the quickrun mode it works)?

    Thank you for your help!
    Erwin

  • sebastiaansebastiaan Posts: 2,813

    Hi Erwin,

    The easiest workaround is probably to run the experiment in a window, but have the window cover the entire display so that it's effectively full screen. You can do this as follows:

    • Select the legacy backend, and click on Backend Settings in the General Properties tab.
    • Set Window position to 0,0.
    • Set Draw window frame to 'no'.
    • Set the resolution of the experiment to the resolution of the display.
    • Run the experiment in a window! (Which will now cover the entire screen.)

    I suspect that the browser should now automatically get the focus when you open a url, just like when you use quickrun.

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.