Is there a way to have a linked file open automatically in a new window? | XM Community
Skip to main content

I'd like to be able to set up my survey so that when a participant gets to a block, a new window will automatically open that is a PDF. Basically the survey block would be an written response question that has key words above it, and the PDF that would open would be an article that those words came from so that the participant can see and scroll through it for reference while writing their answer.
I know that I can include a link in the block that they can click to open the PDF in a new window/tab, but I was hoping to automate that so that the PDF opens without them needing to click the link. From what I heard back from Qualtrics, this isn't a feature built into the system, but could likely be accomplished with by adjusting the HTML of the links. Any help would be much appreciated!
Thanks.

Use the below code in the JS of first question of the block:
window.open("PDF_URL");


Thank you! Sorry, this is probably painfully obvious to those of you with any experience coding!


https://www.qualtrics.com/community/discussion/comment/30149#Comment_30149Two additional questions:
1 - this is working, but it's actually opening two new tabs of the file. Any idea why?
2 - Is there a way to have that window automatically close when they move to the next block? I tried adding a window.close("PDF_URL"); under the page unload javascript, but that didn't do anything. Maybe a window.close at the start of the next block, followed by another window.open command for a new file?
Thank you again!


1 - this is working, but it's actually opening two new tabs of the file. Any idea why? => Since you must be testing in preview mode, the code runs twice once for dekstop view and another for mobile. Try to test using annonymous link, only one tab will get open.
2 - Is there a way to have that window automatically close when they move to the next block? => Use the below code and paste it as shown in the image:
var myWindow;

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

myWindow = window.open("PDF_URL");


});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
myWindow.close();

});
image.png


Leave a Reply