automatically resize to full screen when clicking next button

﹥>﹥吖頭↗ 提交于 2019-12-12 07:07:53

问题


I am trying to insert some javascript code into qualtrics. I want it to resize the user's browser after the user presses the "next" button (this is after a short statement telling the user that the user's browser will be resized). When I run this code with an HTML file in my own browser, it works. However, it does not work in qualtrics. I know it is grabbing the "NextButton" element correctly because I tested the button click with a basic alert. Does anyone know if there is something in qualtrics that blocks this fullscreen function? Is there a way to get around it? My Javascript code is pasted below. Thanks in advance!

Qualtrics.SurveyEngine.addOnload(function()
{

$("#NextButton").click( function()
{
    alert("hi");
    launchIntoFullscreen(document.documentElement); 

});


function launchIntoFullscreen(element) {
  if(element.requestFullscreen) {
    element.requestFullscreen();
  } else if(element.mozRequestFullScreen) {
    element.mozRequestFullScreen();
  } else if(element.webkitRequestFullscreen) {
    element.webkitRequestFullscreen();
  } else if(element.msRequestFullscreen) {
    element.msRequestFullscreen();
  }
}   

});

回答1:


I think you have a conflict between your NextButton click handler and the Qualtrics NextButton click handler. Qualtrics is winning.

The way I've handled similar situations before is to hide the Qualtrics NextButton, and add my own button that executes whatever code I need before it clicks the Qualtrics NextButton.

Something like this:

Qualtrics.SurveyEngine.addOnload(function () {

$('NextButton').hide();
$('NextButton').insert({
    before: "<input id=\"checkButton\" type=\"button\" value=\"  >>  \" title=\"  >>  \">"
}); 
$('checkButton').onclick = function fullScreen() {
    launchIntoFullscreen(document.documentElement); 
    $('NextButton').click();
};

function launchIntoFullscreen(element) {
      if(element.requestFullscreen) {
        element.requestFullscreen();
      } else if(element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
      } else if(element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
      } else if(element.msRequestFullscreen) {
        element.msRequestFullscreen();
      }
}       

});



回答2:


You should check if that Web API is actually supported inside Qualtrics.

try Modernizer or something like this. how to detect a browser supports requestFullscreen

if it's actually supported then the element wasn't valid and requestfullscreen didn't get invoked.



来源:https://stackoverflow.com/questions/33228156/automatically-resize-to-full-screen-when-clicking-next-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!