1

I'm trying to use a function that switches an iframe's source link on Github Pages. It is from here.

The iframe sources are p5.js sketches also hosted on Github Pages. The whole page (121templatetwo) works locally but when pushed to Github Pages, the iframe is empty.

Link to 121templatetwo repo: https://github.com/lilykdonaldson/121templatetwo

Code for iframe switcher (which is also in the repo):

var switcher$ = $('.switcher'),          // select element
    switchTarget$ = $('.switch-target'); // iframe

switcher$.on('change', switchIframeSrc); // event binding

// our functiono to switch the iframe src
function switchIframeSrc() {
  // set the 'src' attribute of the iframe
  // to the value of the selected option
  switchTarget$.attr('src', switcher$.val());
}

// call the method on load
switchIframeSrc();

And the link to the Github Page where the iframe is empty.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107

1 Answers1

0

When you encounter issues like this, your first step should always be to check your developer tools, especially the JavaScript console and the network tabs.

This is where any errors you're getting will show up. In your case, you're getting two errors:

Mixed Content: The page at 'https://lilykdonaldson.github.io/121templatetwo/' was loaded over HTTPS, but requested an insecure script 'http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'. This request has been blocked; the content must be served over HTTPS.

index.js:1 Uncaught ReferenceError: $ is not defined
    at index.js:1

So, your page is loaded over HTTPS, which means it can't load script files over HTTP. This is preventing you from loading JQuery, which is breaking everything else. This works locally because presumably you're loading via a file:// URL.

The quick fix to this is to switch your JQuery URL to HTTPS instead.

But in the future, check out the developer tools.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107