Skip to main content
Inspiring
Sep 15, 2015 8:56 AM UTC
Answered

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

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.

    This topic is closed to new replies. Start a new post to keep the conversation going.
    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    Sep 15, 2015 12:47 PM UTC

    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.


    Execute this onSlideEnter of the first slide:

    if ( window.cpAPIInterface )

    {

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

    }

    9 replies

    TLCMediaDesign
    Inspiring
    Sep 15, 2015 9:21 AM UTC

    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
    Inspiring
    Sep 15, 2015 9:52 AM UTC

    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
    Lilybiri
    Legend
    Sep 15, 2015 9:00 AM UTC
    Inspiring
    Sep 15, 2015 11:13 AM UTC

    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
    Lilybiri
    Legend
    Sep 15, 2015 11:35 AM UTC

    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