Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript] Pojawienie się filmiku youtube po wklejeniu linku
lekosm2
post
Post #1





Grupa: Zarejestrowani
Postów: 141
Pomógł: 0
Dołączył: 9.10.2015

Ostrzeżenie: (0%)
-----


Witajcie, jak zrobić, że gdy wkleję w input link do filmiku youtube to nad tym inputem pojawi się iframe z filmikiem.

Przykład iframe .
  1. <iframe width="560" height="315" src="https://www.youtube.com/embed/JG34rEIyGhs" frameborder="0" allowfullscreen></iframe>


Podacie przykład jak to zrobić?
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


1. Pobrać wartość z tego inputa.
2. Przefiltrować pod kątem poprawność (czy to link do YT).
3a. Jeśli ramki nie ma na stronie, to dodać ją wraz z poprawnym atrybutem src, ustawiony na wartość z punktu 2.
3b. Jeśli ramka jest na stronie, to (zmienić jej wyświetlanie z none na block i) ustawić jej atrybut src.

https://developer.mozilla.org/pl/docs/Web/A...nt/setAttribute
Go to the top of the page
+Quote Post
lekosm2
post
Post #3





Grupa: Zarejestrowani
Postów: 141
Pomógł: 0
Dołączył: 9.10.2015

Ostrzeżenie: (0%)
-----


A zrobisz mi przykład?
Go to the top of the page
+Quote Post
Neutral
post
Post #4





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

Ostrzeżenie: (0%)
-----


  1. <form method="post">
  2. <input type="text" id="text"/>
  3. <input type="button" id="btn" value="add"/>
  4. <input type="button" id="btn2" value="remove"/>
  5. </form>


Kod
function addElement () {
  // create a new div element
  // and give it some content

  var newDiv = document.createElement("iframe");
  newDiv.setAttribute('width',560);
  newDiv.setAttribute('height',315);
  newDiv.setAttribute('src',document.getElementById('text').value);
  newDiv.setAttribute('frameborder',0);
  newDiv.setAttribute('allowfullscreen','allowfullscreen');
  newDiv.setAttribute('id','divek');
  var newContent = document.createTextNode("Hi there and greetings!");
  newDiv.appendChild(newContent); //add the text node to the newly created div.

  // add the newly created element and its content into the DOM
  var currentDiv = document.getElementById("div1");
  document.body.insertBefore(newDiv, currentDiv);
}
function removeElement(){
    document.getElementById('divek').remove();
}
document.getElementById('btn').addEventListener('click',addElement,false);
document.getElementById('btn2').addEventListener('click',removeElement,false);

Template: https://developer.mozilla.org/en-US/docs/We...t/createElement
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 20:03