Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CP8 Question: Can I get the current URL path in a variable?

Engaged ,
Sep 15, 2015 Sep 15, 2015

Hello,

I want to get the current .HTM path and filename into a variable.

An an example would be http://mycompanyserver/training/health_and_safety/infection_prevention.htm

I created a User variable called myurl

On the slide 1 On Exit I used some javascript I found on the internet var myurl = window.location.pathname;

On slide 2 I put a text caption to display the myurl

I published and ran the project from my server.

The result was a blank caption box.

Please could someone suggest what I should be using.

(I do not want to use the Captivate system variable $$cpInfoProjectName$$ as that does not do what I want)

Thank you

Peter

Cardiff (Cold, overcast, windy and rain. A grim day)

Wales

UK.

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

correct answers 1 Correct answer

People's Champ , Sep 15, 2015 Sep 15, 2015

Execute this onSlideEnter of the first slide:

if ( window.cpAPIInterface )

{

window.cpAPIInterface.setVariableValue('myurl', document.location.href)

}

Translate
LEGEND ,
Sep 15, 2015 Sep 15, 2015
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 15, 2015 Sep 15, 2015

Lilybiri

I looked, I read, I tried, I failed.

I looked again, I read again, I tried again, I failed again. (Repeat x 10)

The problem with the example on page Dynamically Leveraging Web Objects in Adobe Captivate 8 - CaptivateDev.com is that it is complicated, and as the writer says "For those of you who don’t know JavaScript, I totally understand that this looks like alien hieroglyphs that will make your head spin." Well my head is spinning!

I used the examples exactly as written, presuming that the variable $$webAddress$$ would be available at the end, but my caption box containing the $$webAddress$$ remained blank.

I extracted the code:

     /* Get the web address from Captivate */ 

     var webAddress = window.cpAPIInterface.getVariableValue('webAddress');

and tried to work with that, but still nothing.

I can sort of see what the example is doing, but it is too complicated for me to make adjustments to indentify where I am going wrong.

From looking at the code I have learned something; I looked up the try and catch commands and now undestand what they do, but the rest is just beyond my understanding.

Any thoughts or suggestions would be really appreciated.

Thank you,

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2015 Sep 15, 2015

I'm sorry, but I'm just a newbie in JS myself, wonder if I will ever master it. Creating a random number is something I use a lot, but the more complicated work flows that Jim was so great at, are beyond my non-programmer mind.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 15, 2015 Sep 15, 2015

Lilybiri,

I see we are in the same boat!

Having looked at the code again I can also see that it is not what I need.

The code shown is for going to a URL, whereas I want to get the current URL from the browser window and utilise it Captivate.

I will persevere and let you know the result.

Peter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Sep 15, 2015 Sep 15, 2015

Execute this onSlideEnter of the first slide:

if ( window.cpAPIInterface )

{

window.cpAPIInterface.setVariableValue('myurl', document.location.href)

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 15, 2015 Sep 15, 2015

Lily and TLC,

Thank you both, this is my result.

    if ( window.cpAPIInterface )

     {

     window.cpAPIInterface.setVariableValue('myURL', document.location.href.substring(document.location.href.lastIndexOf('/')+1))

     }

     window.localStorage.setItem("myCallingMenu",window.cpAPIInterface.getVariableValue('myURL'));

The code looks for the current URL in the browser and then strips out just the filename.

The filename is then placed in a variable named myURL

The contents of myURL are then stored on the hard disk in the browser local storage in a variable named myCallingMenu.

Why do I need this?

I will use this in a menu system.

I have a number of seperate menus (menuDoctor, menuNurse, menuAdmin, menuPharmacy etc etc)

Each of these menus calls projects specific to those job roles.

However, each menu can also call a common project, such as 'infection_prevention'.

When the infection_prevention project finishes I need it to go back to the menu it was called from, (doctor, nurse etc)

So I will use the code above to store the filename of the calling menu in the myCallingMenu variable on the disk, and then when infection_prevention finishes it will read the filename in myCallingMenu and return to the correct menu. (I've got the reading code working as well)

Why do I do it this way?

I don't want to use the Aggrigator thing, I find it too cumbersome.

If I tried to combine all the projects into one file the size would be just too large.

Our network is slow, so small projects work well.

Using individual projects allows me to ammend one section without having to recomplie the entire project.

The PC I run captivate on to create the projects is a bog standard business PC designed for nothing more taxing than word processing, so Captivate is slow, therefore small projects are better.

Large projects crash more than small projects. (I do all my work on my local drive, working across a network crashes even more)

I hope this will be of help to anyone else who needs a similar thing.

Peter

Cardiff (Still overcast and grim)

Wales

UK

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Sep 15, 2015 Sep 15, 2015
LATEST

You should also put the localStorage line inside of the braces as well since it is using the cpAPIInterface.

Also you should be aware that if you use the myCallingMenu variable for any other courses they will overwrite each other. It's best to prepend a course identifier to the localStorage variable.

CourseID.myCallingMenu

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Sep 15, 2015 Sep 15, 2015

You'd want to use document.location.href as it will return the full URL, pathname returns a partial URL.

You also need to get a reference to the Captivate object to set the variable, Are you publishing HTML5, SWF or both?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 15, 2015 Sep 15, 2015

TLC,

Publishing as SWF at the moment, but would like to prepare for HTML 5.

I'm going to plough through the link that Lily provided, and try and pick out the bits of code I need (I am not a programmer).

I will post my results back here. (I may be some time !)

Thank you.

Peter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources