Jump to content

something like lightbox


Q695

Recommended Posts

I have this line of code, but it's redirecting to another page, but I want it to replace the freeze frame of the video:

document.write("<iframe width='420' height='315' src='//www.youtube.com/embed/...' frameborder='0' allowfullscreen></iframe>")

What does the document.write need to say to swap, and not go to another page?

Link to comment
https://forums.phpfreaks.com/topic/283550-something-like-lightbox/
Share on other sites

  • 1 month later...

If you use document.write after the page has loaded, it will rewrite the entire page. Instead, use innerHTML of an html element.

 

e.g.

<div id="my_video_div"></div>

... later in your script ...

document.getElementById('my_video_div').innerHTML = '<iframe ....>';

Now I have this code:

<script>
<?php
if ($_GET['item']){
	echo "
	function show_video($video_name, $video_value)
	{
	document.getElementById('video').innerHTML='$video_name';
	document.getElementById('video').href='$video_value';
	document.getElementById('video').target='_blank';
	}
	";
}


?>
</script>

errors as undefined php variables.

 

After this I will rewrite it to swap an image (1st) with a video (2nd).

The values of the button should be:

<input type='button' onclick='show_video(w3c, w3c.org)' value='Watch'>

It really outputs:


	function show_video(, )
	{
	document.getElementById('video').innerHTML='$';
	document.getElementById('video').href='$';
	document.getElementById('video').target='_blank';
	}
	</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.