1

I have a iframe url that I would like to change based on what the user inputs into the text field. So I have:

<iframe
    src="http://player.twitch.tv/?channel={CHANNEL}"
    height="720"
    width="1280"
    frameborder="0"
    scrolling="no"
    allowfullscreen="true">
</iframe>

I would like to change {CHANNEL} to be what the user inputs into a text field and submits via button. For example, if the user inputs "TestName" into the text field the new iframe URL would become src="http://player.twitch.tv/?channel=TestName"

Not sure how to do this.

1
  • 1
    Do you have any code? We can help you with specific questions to your code but we're not going to write it for you. You can you JavaScript events to change the src attribute of the iframe. Commented Mar 18, 2017 at 3:07

1 Answer 1

1

Try this. Keep in mind the input is not validated/protected.

function changeChannel(){
  document.getElementById("twitchFrame").src = "http://player.twitch.tv/?channel="+document.getElementById("channel").value;
}
<input type="text" id="channel"></input>
<button type="button" onClick="changeChannel();">Change Channel</button>
<iframe
    id="twitchFrame"
    src="about:blank"
    height="720"
    width="1280"
    frameborder="0"
    scrolling="no"
    allowfullscreen="true">
</iframe>

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

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.