Forum Discussion

JimOwen-f418d1f's avatar
JimOwen-f418d1f
Community Member
8 months ago

Set Web Object URL at runtime

I would like to set the URL to a web object at runtime. Basically I want to build a URL in JavaScript based on some variables, then assign the web object to that URL when the slide is displayed. I tried the below code., which did not work. (I'm hard-coding the URL first, just to see if I could do it at all - eventually I will build newURL programmatically.) How do I do it?

var newURL = "https://www.example.com/newpage"; document.getElementById("yourWebObjectID").data = newURL;

  • Hi Jim, you would need to assign the URL to the "SRC" attribute of the iframe associated with the WebObject. For example, the WebObject iframe might look something like this: 

    <iframe data-dv_ref="iframe" data-dv_src="http://www.google.com" src="http://www.google.com" allowfullscreen="" class="shown " tabindex="0" aria-hidden="false"></iframe>

    So you would have to first get the iframe. I'm using the src attribute value to make sure I get the correct iframe.

    const $newurl = "https://community.articulate.com/"
    const $iframe = document.querySelector("iframe[src='http://www.google.com']");
    $iframe.setAttribute("src", $newurl);