WeBWorK Problems

Loading nonsecure javascript library on secure server

Loading nonsecure javascript library on secure server

by Paul Seeburger -
Number of replies: 6
There is probably info on this somewhere, but I couldn't quickly find it.

I am trying to use the JSXGraph library in a problem.  It works great, but my WeBWorK server is secure (using https) and it loads the JavaScript library from a non-secure website (using http).  It worked without a warning on my Mac, but on Chrome on my Windows machine it failed silently.  I looked at the JavaScript console and it failed because of the JavaScript library being loaded from a non-secure site (although the WeBWorK problem was loaded over a secure site).

I assume one way to solve this is to place the JavaScript library in my local file system and load it from my problems.  This makes the problems more difficult to share in the OPL though.  The instructors (or admins) would need to load the JavaScript libraries onto their local file systems/servers for these problems to work. 

Is there a solution others have found to this that may be easier to use for sharing problems to the OPL?

Also, what web address do I use to access JavaScript files I save in a folder in my templates folder of my course file system?  I don't want to have to store the library in the same folder as the problem itself.
In reply to Paul Seeburger

Re: Loading nonsecure javascript library on secure server

by Davide Cervone -
The JSXGrpah CDN supports both https and http protocols, so you could link to it using https, or use the protocol agnostic form, e.g.
    //cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.99.1/jsxgraphcore.js
as they recommend on their download page.
In reply to Davide Cervone

Re: Loading nonsecure javascript library on secure server

by Paul Seeburger -
Thanks, Davide!

This reference worked perfectly for JSXGraph.

But what if I create my own JavaScript code library or find another library that does not have its own secure web address?

Is there a way to reference files directly in my course file structure from elsewhere on the web or (more specifically) from within my problems?

Or do I need to get them stored on the server by an administrator of the server?

Thanks!

Paul
In reply to Paul Seeburger

Re: Loading nonsecure javascript library on secure server

by Davide Cervone -
There is an html directory in your course (use the ^ button in the File Manager to get to the course home directory -- you should see html there). you can put your own files there. There is a variable $htmlURL in PG that refers to this directory, so you should be able to use that to access your code.
In reply to Paul Seeburger

Re: Loading nonsecure javascript library on secure server

by Steve Dalton -
Thank you so much for asking this question, as I didn't realize that was happening to me: I use the HTTPS everywhere extension and I couldn't get my JXGraph questions to load!
In reply to Steve Dalton

Re: Loading nonsecure javascript library on secure server

by Glenn Rice -
Steve: Have you figured this out? If you are using my file graph_line.pg from the other thread then change the line
<script type='text/javascript' src='http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js'></script>
to
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.99.1/jsxgraphcore.js"></script>

For the css file you will either have to make that file available locally on your server or include the relevant portion of that file (the jsxgraph box style) directly in your pg file.

In reply to Glenn Rice

Re: Loading nonsecure javascript library on secure server

by Steve Dalton -
Hi Glenn,

Thanks for your reply. Yes, everything worked just fine after the change you mentioned.

I do have a related question though: The CSS file seems to be working just fine, but where would I include the CSS file locally? I don't have an html directory (doing a trial run off of the MAA's servers), so can I just include it in the problem set directory?

Thanks again,
Steve