Highlighted

Javascript to put content of WebObject into variable or array?

Engaged ,
Nov 06, 2018

Copy link to clipboard

Copied

Captivate 9, fully updated.

HTML5 output only.

Non-responsive only.

Hello.

I have Captivate slide accessed from our training server.

The slide has a WebObject  that displays information from a hospital Patient System on a different server.

(I have no control over the Patient System, it is created and managed by a third party.)

As a student task I need the student to browse the patients in the WebObject, and then click the Task Finished button on the slide.

When Task Finished is clicked, I need to identify the PatientID so that I can use it in Captivate.

The PatientID is always located in the HTML code <label id="PatientID">ABC123</label>

I know how to create all of this in Captivate.

The only part of this that I cannot do is getting the content of the WebObject into a javascript variable or array.

Once I have the content in a javascript variable or array, I know how to search through it to locate the PatientID.

My Question:

I have searched online and found lots of Javascript information about getting the content of an iFrame, but to be honest I'm finding it confusing, and I just don't know where to start.

What I would appreciate is for just a quick and dirty pointer as to how to start this.

Thank you

Peter

(The URLs in the image below are dummies just for example.)

ScreenShot_440a.png

Adobe Community Professional
Correct answer by TLCMediaDesign | Adobe Community Professional

Create a variable in Captivate where you want to store the ID;

Then execute this JavaScript on the Task Finished button:

var getFrame = document.getElementsByTagName("IFRAME")[0];

var elem = getFrame.contentWindow.document.getElementById("PatientID");

window.yourVariable = elem.innerHTML;

Change yourVariable to the variable you create.

Note: You may run into CORS issues.

Views

301

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Javascript to put content of WebObject into variable or array?

Engaged ,
Nov 06, 2018

Copy link to clipboard

Copied

Captivate 9, fully updated.

HTML5 output only.

Non-responsive only.

Hello.

I have Captivate slide accessed from our training server.

The slide has a WebObject  that displays information from a hospital Patient System on a different server.

(I have no control over the Patient System, it is created and managed by a third party.)

As a student task I need the student to browse the patients in the WebObject, and then click the Task Finished button on the slide.

When Task Finished is clicked, I need to identify the PatientID so that I can use it in Captivate.

The PatientID is always located in the HTML code <label id="PatientID">ABC123</label>

I know how to create all of this in Captivate.

The only part of this that I cannot do is getting the content of the WebObject into a javascript variable or array.

Once I have the content in a javascript variable or array, I know how to search through it to locate the PatientID.

My Question:

I have searched online and found lots of Javascript information about getting the content of an iFrame, but to be honest I'm finding it confusing, and I just don't know where to start.

What I would appreciate is for just a quick and dirty pointer as to how to start this.

Thank you

Peter

(The URLs in the image below are dummies just for example.)

ScreenShot_440a.png

Adobe Community Professional
Correct answer by TLCMediaDesign | Adobe Community Professional

Create a variable in Captivate where you want to store the ID;

Then execute this JavaScript on the Task Finished button:

var getFrame = document.getElementsByTagName("IFRAME")[0];

var elem = getFrame.contentWindow.document.getElementById("PatientID");

window.yourVariable = elem.innerHTML;

Change yourVariable to the variable you create.

Note: You may run into CORS issues.

Views

302

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 06, 2018 0
Adobe Community Professional ,
Nov 06, 2018

Copy link to clipboard

Copied

Create a variable in Captivate where you want to store the ID;

Then execute this JavaScript on the Task Finished button:

var getFrame = document.getElementsByTagName("IFRAME")[0];

var elem = getFrame.contentWindow.document.getElementById("PatientID");

window.yourVariable = elem.innerHTML;

Change yourVariable to the variable you create.

Note: You may run into CORS issues.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 06, 2018 0
Engaged ,
Nov 07, 2018

Copy link to clipboard

Copied

@TLCMediaDesign

Thank you, your code worked perfectly, and as you predicted I ran into the CORS issue.

I don't think I can get around this using Javascript, so maybe I can figure something out in PHP.

Unfortunately the website I want to put in a frame is on a different domain to me, and it uses the HTML shown below, and I guess that means I can't do what I am attempting.

<meta http-equiv="X-Frame-Options" content="SAMEORIGIN" />

Once again, thank you for you help, it is always much appreciated.

Peter

Note to anyone who wants to use this code: getElementById"PatientID"); was missing a bracket getElementById("PatientID");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0
Adobe Community Professional ,
Nov 07, 2018

Copy link to clipboard

Copied

Is Patient Systems a client?

It would be very easy for them to add your URL to allow access.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0
Engaged ,
Nov 07, 2018

Copy link to clipboard

Copied

The patient system in a national system for the entire country, holding millions of patient records.

It is designed and maintained by a totally independent third party, and is nailed down with an abundance of security.

I know that if I put in a request for my URL to be allowed access for training purposes, it would be refused for very good reasons, as the more holes a system has then the less secure it is.

The onus is on me to think of an alternative method of achieving my goal, and I am some way towards that at the moment.

Cheers

Peter

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0