Can you create a dynamic iFrame URL using student user ids?

Jump to solution
sharper
Community Novice

I'm a new Canvas admin and am trying to figure if I can annotate iFrame URLs with user information. I have a survey that I'd like to embed in a Canvas page; the first question is hidden and ideally would populate with the student's Canvas user ID. Theoretically, the HTML content of the page would look like the following, but the portion in pink would be dynamic to the viewing user's ID. Is this something that (1) is doable in Canvas and (2) someone with limited API/LTI knowledge would be able to easily implement? Thanks!

<iframe src="https://survey.clicktools.com/app/survey/go.jsp?iv=3vo8w3wtc10a5&q1=user_id" width="100%" height="600"></iframe></p>

1 Solution
ColinMurtaugh
Community Champion

Hi Shanna --

You could accomplish this using either some custom Javascript or by building a simple LTI tool. For the Javascript approach, you could take advantage of the fact that every Canvas page has some special Javascript variables available , including one that contains the user ID of the currently logged-in user:

ENV['current_user_id']

(You can see all of these special environment variables by opening your browser's developer tools console and typing 'ENV') Your custom Javascript could look for an iframe with your clicktools URL in the src, and append the value of the ENV['current_user_id'] variable.  The pros of this approach are that it'd be fairly simple code to write, and it wouldn't require you to run any server-side software. The cons are that the Javascript code would probably need to run on every page, and that using Javascript to manipulate a page's content like this can be brittle (it can stop working if the page's markup changes in unexpected ways). 

You could write an LTI tool that would accomplish something similar. When a user clicks on a link to an LTI tool that's installed in an LMS, the LMS generates an HTTP POST request to the tool.  This is called the LTI launch request, and it passes a bunch of different parameters from the LMS to the tool, including the user ID.  You could write a very simple LTI tool that receives these parameters and then redirects the user to the clicktools URL with the user ID appended, and the survey would get loaded in an iframe inside of Canvas. The pros of this approach are that you'd be using a stable, standard protocol to receive the user ID from Canvas. The cons are that the code would be more complicated to write, and you'd need to have a server on which to run it (and all of the complexity that comes along with that). 

Good luck!

--Colin

View solution in original post