1

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("https://player.twitch.tv/?channel=" + channel, url)
$('#Chat').attr("https://www.twitch.tv/" + channel + "/chat?popout=", url)

2 Answers 2

4

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', "https://player.twitch.tv/?channel=" + channel);
$('#Chat').prop('src', "https://www.twitch.tv/" + 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.

Sign up to request clarification or add additional context in comments.

1 Comment

No problem, glad to help
1

Another method to change source path of iframe.

Please check it below.

$('#Stream').attr("src","https://player.twitch.tv/?channel=" + channel);
$('#Chat').attr("src","https://www.twitch.tv/" + channel + "/chat?popout=");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.