-
Hello, I was looking for a way to do the following thing in jsPsych. I'm wondering if that's possible: When using a multiple choice or instructions plugin, i want to divide the screen vertically into two halves, embed a link on the left part of the screen and use the regular multiple choice/instructions plugin on the right. I tried it with instructions plugin by putting some html code in "pages" but when I did it, the "next" button was not clickable anymore. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @sebgok, I was able to find a solution by using jsPsych's ability to display in a specific HTML element on the page. I set up a page with a <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="jspsych-6.3.0/jspsych.js"></script>
<script src="jspsych-6.3.0/plugins/jspsych-html-button-response.js"></script>
<script src="jspsych-6.3.0/plugins/jspsych-call-function.js"></script>
<link
rel="stylesheet"
type="text/css"
href="jspsych-6.3.0/css/jspsych.css"
/>
<style>
#iframe-target {
width: 48vw;
height: 100vh;
float: left;
display: none;
}
#jspsych-target {
height: 100vh;
width: 100vw;
margin: 0;
padding: 0;
float:right
}
</style>
</head>
<body>
<iframe id="iframe-target" src="https://www.jspsych.org">
</iframe>
<div id="jspsych-target"></div>
</body>
<script src="task.js"></script>
</html> The iframe starts as not displayed ( var trial = {
type: 'html-button-response',
stimulus: 'This is before the iframe shows up',
choices: ['Hi there']
}
var start_iframe = {
type: 'call-function',
func: function(){
document.querySelector('#iframe-target').style.display = 'block';
document.querySelector('#jspsych-target').style.width = '48vw';
}
}
var quiz = {
type: 'html-button-response',
stimulus: '<p>Take a look at the webpage on the left. Is it helpful?</p>',
choices: ['No', 'Yes']
}
var quiz2 = {
type: 'html-button-response',
stimulus: '<p>Second question. Is it complicated?</p>',
choices: ['No', 'Yes']
}
var stop_iframe = {
type: 'call-function',
func: function(){
document.querySelector('#iframe-target').style.display = 'none';
document.querySelector('#jspsych-target').style.width = '100vw';
}
}
var last = {
type: 'html-button-response',
stimulus: 'Bye!',
choices: ['Done']
}
jsPsych.init({
timeline: [trial, start_iframe, quiz, quiz2, stop_iframe, last],
display_element: 'jspsych-target'
}) Here's the demo of the task. You can see my code on Glitch. |
Beta Was this translation helpful? Give feedback.
-
Thank you, Josh! This code works great.
Here is how the style changes from without the consent div to with the consent div: |
Beta Was this translation helpful? Give feedback.
Hi @sebgok,
I was able to find a solution by using jsPsych's ability to display in a specific HTML element on the page.
I set up a page with a
<div>
for the jsPsych experiment and an<iframe>
of content: