Set Web Object URL at runtime

Feb 11, 2024

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;

1 Reply
Sam Hill

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);