Jones King Jones King - 2 years ago 162
Javascript Question

Edit iframe src using jQuery

Why won't my code paste my iframe src? It is just empty in HTML.

<iframe id="Stream" src="" class="col-sm-12" frameborder="0" scrolling="no"></iframe>
<iframe id="Chat" src="" frameborder="0" scrolling="no"></iframe>

$('#Stream').attr("" + channel, url)
$('#Chat').attr("" + channel + "/chat?popout=", url)

Answer Source

Your syntax for calling the attr() method is incorrect. The first argument is the name of the attribute and the second should be the value you want to set. It's also preferred to use the prop() method where possible, as it would be in this case.

$('#Stream').prop('src', "" + channel);
$('#Chat').prop('src', "" + channel + "/chat?popout=");

attr() method
prop() method

Note that this may still not work correctly if the requested domain has disallowed itself to be rendered in an iframe on a third-party website using X-Frame-Options.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download