• Register
  • Login
  • Pricing
  • Support
    • Support
    • Tutorials
    • Blog
    • Guide
    • Support Forum
  • Create PollUnit

How can I scroll the iFrame to the top when the content changes?

When embedding PollUnit on your website, it may be useful to change the scroll position of your webpage when the content of PollUnit changes. For example, when switching from an overview to a detailed view in a photo contest and the height of the iFrame changes significantly. Unfortunately, PollUnit cannot remotely control your website and scroll to a different position. This needs to happen on your website.

To make this work, you can listen for the load event of the iFrame using JavaScript and then trigger a function. In our example, we call the function »customScrollFunction«, and the iFrame is assigned the ID »pollUnitIframe«.

The JavaScript that triggers the function could look like this:

document.getElementByClassName('pollUnitIframe')[0].onload = function() {
  customScrollFunction();
};

The actual function that scrolls the iFrame could look like this:

customScrollFunction = function() {
 const element = document.querySelector('#pollUnitIframe');
 if (element) {
  element.scrollIntoView({ behavior: 'smooth', block: 'start' }); 
 }
};

Please note that we are selecting the iFrame again based on our example ID. In some cases, it may be necessary to scroll a parent element of the iFrame or consider an offset. This could be the case, for example, if your website has a fixed header. Then you would need to adjust our example code accordingly.

Further tutorials

Create your first poll

Advanced poll features

Advanced survey branching logic

Distribute tasks online

Cast votes and rate options

Find a date

Vote on images

Create your own theme

Polls with your own logo

Evaluate your PollUnit

Dot Voting

Range Voting

Polls on your own website

Live Voting

Reach a consensus

Manage orga­nizations

Prevent multiple participation

Donations and participation fees

Are you ready?

Create PollUnit Register

Tools

  • Voting
  • Surveys
  • Free Tables
  • Collect Ideas and Feedback
  • Photo Contests
  • Video Contests
  • Music Contests
  • Landing Page
  • Pairwise Comparison
  • Advent Calendar
  • PollUnit Lab

Support

  • Get started
  • PollUnit Help
  • Tutorials
  • Examples
  • Support Forum
  • support@pollunit.com

Tutorials

  • Create your first poll
  • Advanced poll features
  • Advanced survey branching logic
  • Distribute tasks online
  • Cast votes and rate options
  • Find a date
  • Vote on images
  • Create your own theme
  • Polls with your own logo
  • Evaluate your PollUnit
  • Dot Voting
  • Range Voting
  • Polls on your own website
  • Live Voting
  • Reach a consensus
  • Manage orga­nizations
  • Prevent multiple participation
  • Donations and participation fees

Legal

  • Privacy policy
  • Terms of use
  • Imprint

PollUnit

  • PollUnit Blog
  • About PollUnit
  • Press kit
  • Deutsch
    German
  • English
    English
  • © PollUnit
  • Register
  • Login
  • Pricing
  • Support
    • Support
    • Tutorials
    • Blog
    • Guide
    • Support Forum
  • Create PollUnit