Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

jQuery embed src ändern

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

so sieht mein Code aus:


<object id="frameobj" width="520" height="300">

<embed id="movieclip" src="http://www.youtube.com/v/xxrbQxZtJGw?version=3&hl=de_DE" type="application/x-shockwave-flash" width="520" height="300" allowscriptaccess="always" allowfullscreen="true"></embed>

</object>


<?php

echo "<a onclick='change()' id='vidbtn'>Klick mich</a>";

?>


  <script type="text/javascript">

  function change(){

    $("#movieclip").attr('src', 'http://www.youtube.com/v/F47oG7Yh7_s?version=3&hl=de_DE')

  }

  </script>

Ich habe ein eingebettetes Youtubevideo und möchte durch ein Clickevent auf das a-Tag ein Video wechsel auslösen. Mein derzeitiges Problem besteht darin, dass das "object" Element verschwindet. Ich mache sicher einen grundlegenden Fehler, jedoch finde ich ihn nach 3 tägigen Mühen immer noch nicht. Hat jemand eine Idee, worin mein Fehler liegt oder kann sogar einen anderen Lösungsweg aufzeigen?!

Ich hoffe ich habe mich einigermaßen klar ausgedrückt.

liebe grüße String

Man kann das src Attribut eines embed Tags nicht ändern, es ist read-only.

Du könntest aber mit append() dynamisch einen neuen embed Tag einfügen.

Und bitte verwende die jQuery event Listener, die sind sooo toll ;-)


<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

	$('.changeVideo').click(function() {

		$('#frameobj embed').remove();

		$('<embed id="movieclip" src="http://www.youtube.com/v/F47oG7Yh7_s?version=3&hl=de_DE" type="application/x-shockwave-flash" width="520" height="300" allowscriptaccess="always" allowfullscreen="true"></embed>').appendTo('#frameobj');

	});

});

</script>


<object id="frameobj" width="520" height="300">

	<embed id="movieclip" src="http://www.youtube.com/v/xxrbQxZtJGw?version=3&hl=de_DE" type="application/x-shockwave-flash" width="520" height="300" allowscriptaccess="always" allowfullscreen="true"></embed>

</object>


<a href="#" class="changeVideo">klick mich</a>

  • Autor

Sehr schön, vielen Dank für diesen Tipp, es funktioniert einwandfrei!

Eine Frage hätte ich jedoch noch, wie kann ich der jQuery-Function etwas übergeben, also beispielsweise den Link des jeweilig angeklickten a Tags. Das Clickevent wird ja durch die Klasse abgefangen, daher bekomme ich keine Variable oder Wert übergeben.

Grüße String

Innerhalb der click event listener Funktion kannst du per $(this) auf das angeklickte Element zugreifen.


$(this).attr('href')

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.