cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sharper
Community Member

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

Jump to solution

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

Accepted Solutions
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

7 Replies
Stefanie
Community Team
Community Team

Hi,  @sharper  Welcome  to the Canvas Community! I've shared your question with the https://community.canvaslms.com/groups/designers?sr=search&searchId=4ee729d6-7236-4e28-81b1-41cc0414... group to see if anyone there has devised an innovative way to accomplish this.

sharper
Community Member

Thank you, stefaniesanders‌!

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

Wow - I never knew about ENV['current_user_id'] @colinmurtaugh - thanks for sharing!

Hi @Colin Murtaugh, I think maybe you can answer my question

Thanks for yours collaborations

aakash
Community Participant

I'm also checking similar question.

Now i'm successfully integrated LTI ,it's working fine

but i'm trying to pass values through Iframe without LTI. Is there any possibility to pass ENV varibale?

<iframe src="https://dummysite.com?userid=ENV['current_user_id']" width="100%" height="600"></iframe>

 

I was tried above one, that is not working. please give me some suggestion

Thanks

lawd
Community Participant

I don't know if this helps, but you can access the user's id by grabbing the ENV.current_user.id  Javascript object. How you can dynamically build a url for an iframe, that's a little more difficult, with Canvas scrubbing Javascript created within the RCE. LTI would be the best approach, but maybe this helps.