Changing src in an Iframe

1

Good morning, friends. I am making a page where there will be some videos from youtube, and with that I will have some links that when activated should pass the respective video into my iframe. But in the whole process, clicking the link in the video, it goes to the entire screen and not into the iframe. Here is the code:

function trocaSrc($a) {
    document.getElemtById("iframe1").src = $a.href;
    return false;
}

And the links:

<div>
<a href="https://www.youtube.com/embed/18WLEZZVaWY" onClick="return trocaSrc(this);">Video 1</a>
<a href="https://www.youtube.com/embed/0CleeB4bY7U"; onClick="return trocaSrc(this);">Video 2</a>
</div>

I can not find where I'm going wrong ... Thanks in advance for the friends who can afford their time to respond.

    
asked by anonymous 16.05.2018 / 17:17

1 answer

0

Syntax error:

document.getElemtById

The correct one would be:

document.getElementById

As the error happens before return false; , the link is directing the page to the Youtube URL that is in href .

  

In the example below the video will not appear due to restrictions of the   snippet, but note that the link is not redirected.

function trocaSrc($a) {
    document.getElementById("iframe1").src = $a.href;
    return false;
}
<div>
<a href="https://www.youtube.com/embed/18WLEZZVaWY" onClick="return trocaSrc(this);">Video 1</a>
<a href="https://www.youtube.com/embed/0CleeB4bY7U"; onClick="return trocaSrc(this);">Video 2</a>
</div>
<iframe id="iframe1"></iframe>
    
16.05.2018 / 18:13