Please try not to use adblocker for this small site. Thanks

Sunday, 16 June 2019

Display Random Pictures Texts and videos with javascript

Are you looking for a script that shows random texts, pictures and videos from YouTube and Facebook? Well, you've come to the right place then. Here I'll show you small javascript which can do all those stuffs.

Random picture examples

At the above example you can see every time you refresh this page it shows a different picture and the script looks like this.

<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "<img src='https://3.bp.blogspot.com/-l9610w4pzOk/XMnv3lso0-I/AAAAAAAACeI/sB0VQgjRAVszNfUGHXRZvStUCC4tRWyJACLcBGAs/s320/Xiaomi-Mi-A1.png'>";
r_text[1] = "<img src='https://4.bp.blogspot.com/-f9QHK5gRBRM/WqRonLkcp9I/AAAAAAAACYE/2mf8AQ8rjOsaVmB84dmu1CHkYbfAvASEACLcBGAs/s320/File_transfer_from_Xiaomi_Mi_A1_004.png'>";
r_text[2] = "<img src='https://2.bp.blogspot.com/-_WAnOWFUmlE/WqRnO3uk_GI/AAAAAAAACXs/zG7hnIBQZFkQ9GkobvvPd2BruDUixM0CgCLcBGAs/s320/File_transfer_from_Xiaomi_Mi_A1_003.png'>";
var i = Math.floor(3*Math.random())

document.write(r_text[i]);
//-->
</script>

Remember to edit the places where it's been colored as green. If you add a line, make sure you add a number too and at the end add total sum where the number 3 Math.floor(3*is.

<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "<img src='pic1.png'>";
r_text[1] = "<img src='pic2.png'>";
r_text[2] = "<img src='pic3.png'>";
var i = Math.floor(3*Math.random())

document.write(r_text[i]);
//-->
</script>

Script for showing random texts.
<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "Banana";
r_text[1] = "Mango";
r_text[2] = "Orange";
r_text[3] = "Facebook";
r_text[4] = "YouTube";
r_text[5] = "Whatsapp";
r_text[6] = "Amazing Tips247";
var i = Math.floor(7*Math.random())
document.write(r_text[i]);
//-->
</script>

Script for showing random Facebook videos.
<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "<iframe src='https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FJayShettyIW%2Fvideos%2F447693092698247%2F&show_text=0&width='380' width='380' height='476' style='border:none;overflow:hidden' scrolling='no' frameborder='0' allowTransparency='true' allowFullScreen='true'></iframe>";
r_text[1] = "<iframe src='https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FBenPhillipsUK%2Fvideos%2F452068408702013%2F&show_text=0&width='380' width='380' height='476' style='border:none;overflow:hidden' scrolling='no' frameborder='0' allowTransparency='true' allowFullScreen='true'></iframe>";
r_text[2] = "<iframe src='https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FPrinceEa%2Fvideos%2F435397637256907%2F&show_text=0&width='380' width='380' height='476' style='border:none;overflow:hidden' scrolling='no' frameborder='0' allowTransparency='true' allowFullScreen='true'></iframe>";
var i = Math.floor(3*Math.random())
document.write(r_text[i]);
//-->
</script>

Examples of random Facebook videos


Note:
When you add Facebook or YouTuve embedding codes change " into '. As you can see in the above script.

<iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FBenPhillipsUK%2Fvideos%2F452068408702013%2F&show_text=0&width="476" width="476" height="476" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe>

Script for showing random YouTube videos.
<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "<iframe width='560' height='315' src='https://www.youtube.com/embed/WTn8XzjGJHk' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
r_text[1] = "<iframe width='560' height='315' src='https://www.youtube.com/embed/_JUr4NsPZ_0' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
r_text[2] = "<iframe width='560' height='315' src='https://www.youtube.com/embed/1jFMroHSi0Y' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
var i = Math.floor(3*Math.random())
document.write(r_text[i]);
//-->
</script> 

Examples of random YouTube videos


No comments:

Post a Comment