OK so im trying to have a webpage that rotates every 30 seconds now i have what i need for this but instead of using an array like in what i have now see code below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rotating Page</title>
<style type="text/css">
* {
margin:0;
padding:0;
border:0;
}
html, body, iframe {
height:100%;
width:100%;
overflow:hidden;
}
</style>
<script type="text/javascript">
var pages = new Array(); // this will hold your pages
pages[0] = 'MY-LINK-HERE';
pages[1] = 'MY-LINK-HERE';
pages[2] = 'MY-LINK-HERE';
pages[3] = 'MY-LINK-HERE';
pages[4] = 'MY-LINK-HERE';
pages[5] = 'MY-LINK-HERE';
var time = 30; // set this to the time you want it to rotate in seconds
// do not edit
var i = 1;
function setPage()
{
if(i == pages.length)
{
i = 0;
}
document.getElementById('holder').setAttribute('src',pages[i]);
i++;
}
setInterval("setPage()",time * 1000);
// do not edit
</script>
</head>
<body>
<iframe id="holder" src="MY-SPLASH-PAGE-HERE" frameborder="0" scrolling="no"></iframe>
</body>
</html>
where in MY-LINK-HERE for the pages array i would like to use my rss link and get the list of links and add them to the pages array or something similar
my rss link is http://directitpros.com/cbm/wp/?feedpages
so i just want to load the text in the pages variable
It took me some time but I got it (tested and working)
This example uses jQuery and jGFeed.
jGFeed is a plugin for jQuery to do anything you want with RSS feeds.
In the HTML source you can get the URL of the plugin to save it.
Observations:
1. Your RSS link is not working properly, please check it!
(http://directitpros.com/cbm/wp/?feedpages)
When using your link I receive this error from the plugin I am using in browser console:
"Uncaught TypeError: Cannot read property 'feed' of null"
2. Make sure the links you want to use in iframe are able to browse by iframe:
Example:
If URLs are not able to browse by iframe you will get this message in your browser console and your iframe will be empty:
"Refused to display document because display forbidden by X-Frame-Options."
3. If you find a working RSS url and links from it fit the above requirements, use this live example I made to test:
http://jsfiddle.net/oscarj24/qWdqc/
(Check browser console and check messages that will appear)
Let's go with the code :-)
HTML:
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="http://dl.dropbox.com/u/15208254/stackoverflow/jquery.jgfeed.js" type="text/javascript"></script>
<iframe id="holder" src="" frameborder="0" scrolling="no"></iframe>
CSS:
html, body, iframe {
height:100%;
width:100%;
overflow:hidden;
}
JS:
// Array containing pages
var pages = new Array();
// Time in seconds to rotate pages
var time = 30;
// Variable for loop purpose
var i = 1;
$(function(){
$.jGFeed('http://working-rss-url',
function(feeds){
// Check for feeds
if(!feeds){
// There was an error, remote url not ok or no feeds
return false;
}
// Do whatever you want with feeds here
for(var i=0; i<feeds.entries.length; i++){
var entry = feeds.entries[i];
// Fill array with RSS entries
pages.push(entry);
}
// If array contains urls
if(pages.length != 0){
// Rotate pages every 'x' seconds
setInterval(function() {
if(i == pages.length){
i = 0;
}
// Replace iframe scr with RSS entry link every 'x' seconds
$('#holder').attr('src', pages[i].link);
i++;
}, time * 1000);
}
}, 5); // Number of feeds you want to recover
});
Hope this helps.
Related
re this post AJAX Post to self in PHP
When using exit() doesn't something have to be printed before this call?
I have written markup/ph with references to external css php scripts. The script uses print (or echo) and a
call to header('type: text/css'). Isn't this useful or necessary in self processing php pages? I find
them endlessly useful. A whole site can be displayed in any state by one page using get queries and posts
from forms. I remember the text I was reading early on when beginning to learn php asserted that when
the page submits to itself, the browser will automatically use asynchronous requests. But in certain situations
an explicit ajax call is useful.
Here is what I am doing and what I am trying to do.
I have a text field and a button in a page
I write text to the text field and click the button
The javascript click event handler for the button gets the text field value
and appends it to a get query attached to the url in the request. The method is get
edit: to specify the environment in which this has been successful.
I am using Firefox v12.0 On Mac OSX with pre-installed apache server on local machine.
(anyone with a Mac running OSX, there is a pre installed apache server, but activating php requires
editing the httpd.com file to un comment the line(s) that load the php module. Also, there is a line
that tells Apache what extensions to use to look for and execute php code. You also must tell it
to take index.php as an index file to run the php in it and have it act as a directory index file)
the javascript code:
function _FETCH()
{
this.init = function(oName, elem, txt)
{
var but = document.getElementById(elem);
but.addEventListener('click', function(){ oName.req('GET', self, '', null, oName, txt) } )
}
this.req = function(method, url, type, msg, oName, txt)
{
var field = document.getElementById(txt);
url+="?ajxTst="+encodeURIComponent(field.value);
var it = new XMLHttpRequest();
it.open(method, url, type);
it.setRequestHeader('Content-Type', 'text/plain');
it.onreadystatechange = function()
{
var elem = document.getElementById('well');
switch(it.readyState)
{
case 0:
case 1:
break;
case 2:
case 3:
elem.childNodes[0].data = " waiting";
break;
case 4:
oName.handleResponse(it.responseText);
break;
default:
alert('ajax processing error');
break;
}
}
it.send(msg);
}
this.handleResponse = function(resp)
{
var elem = document.getElementById('well');
elem.childNodes[0].data = " "+resp;
}
}
The php, javascript and markup in the page:
<?php
/*
created 11/4/2014
*/
$_self = basename($_SERVER['PHP_SELF']);
if($_POST || $_GET)
{
if($_GET['ajxTst'])
{
header("Content-Type: text/plain");
print $_GET['ajxTst'];
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>JS lab 2</title>
<link rel="stylesheet" type="text/css" href="local.css" media="screen" />
<script type="text/javascript" src="local.js">
</script>
<script type="text/javascript">
//<![CDATA[
var self = "<?php print $_self; ?>";
window.onload = function()
{
var ajx = new _FETCH();
ajx.init(ajx, 'send', 'tlk');
}
//]]>
</script>
</head>
<body>
<div class="panel">
<p class="title">Js Lab 2</p>
<p class="norm">Lab 3 home</p>
<p class="norm">Work with ajax and self processing page (this)</p>
<hr />
<p class="norm" id="well"> idle </p>
<p class="norm">
<input type="text" id="tlk" value="" /><input type="button" id="send" value="send" />
</p>
</div>
</body>
</html>
I hope That someone looking for this will find it. It took me a while to get it right
I need a pop up (facebook like share box) to be displayed when the the youtube video stops.
I already have lots of videos on my wordpress website. I need this to work for all my previous videos.
I've already tried this from another post here:
<html>
<head>
<title>YT Test</title>
<script type="text/javascript">
<!--
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player) after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'ecccag3L-yw',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// The API will call this function when the video player is ready.
function onPlayerReady(event) { /* do nothing yet */ }
// The API calls this function when the player's state changes.
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
// insert appropriate modal (or whatever) below
alert('I hope you enjoyed the video')
}
}
-->
</script>
</head>
<body>
<div id="player"></div>
</body>
<html>
isn't helping. This works only for one video. ecccag3L-yw in this case.
Can someone help me do this right?
here is an example of what I need. http://www.broascadilie.ro/index.php/video/item/29208-c%C3%A2nd-ea-are-chef-%C8%99i-tu-nu-when-she-is-in-the-mood-and-he-isnt
after the video ends, a pop up comes up for users to like and/or share.
This one isn't hard. You need to change videoId: 'ecccag3L-yw' to videoId: '<?php echo $id?>'
Also you need to make sure that in the $id variable is stored your video ID. Since you are using wordpress you should just make a connection to the database and get the value you are interested.
So about after the <title></title>
i need to refresh image in every 5 sec. without flicker. so search google and find some solution.
but that Code refresh image and without flicker but it stop refresh image after some time.
some time its stop refresh image after 1 min, some time after 3 min some time after 15 min.
Here is my code
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="JavaScript">
var x = 0,
y = 0;
var canvas, context, img;
function timedRefresh() {
canvas = document.getElementById("x");
context = canvas.getContext("2d");
img = new Image();
img.src = "CC4.png?" + Math.random();
img.onload = function () {
context.drawImage(img, x, y);
x += 0;
y += 0;
setTimeout('timedRefresh()', 5000);
};
}
window.onload = timedRefresh;
</script>
</head>
<body id="home" onload="setTimeout('timedRefresh()',5000)">
<canvas id="x" width="800" height="590"/>
</body>
</html>
I guess it is a network issue so it stops when it can't load the image. Try adding
img.onerror = function(){ setTimeout('timedRefresh()', 1000); }
so it retries the load even if there was an issue
Is there a way to track play counts for embedded videos? Ideally without resorting to a thumbnail linked to launch the embed / iframe code.
Example (try it yourself on jsFiddle):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="log"></div>
<ul>
<li class="video" id="video1"><iframe width="480" height="390" src="http://www.youtube.com/embed/z6lL83wl31E" frameborder="0" allowfullscreen></iframe><li>
<li class="video" id="video2"><iframe src="http://player.vimeo.com/video/28231570?title=0&byline=0&portrait=0" width="400" height="225" frameborder="0"></iframe></li>
<li class="video" id="video3"><embed flashVars="playerVars=autoPlay=no" src="http://www.metacafe.com/fplayer/3153323/the_three_stooges_minisode_beer_barrel_polecats_season_1_episode_0008.swf" width="440" height="248" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_3153323" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></li>
</ul>
<script>
/* Here's what I've tried so far: */
$('.video').mouseover(function(){
$('#log').html('Mouseover!');
/*alert('Track mouseovers instead? Is this the best I can do?');*/
});
$('.video').mouseout(function(){
$('#log').html(' ');
});
$('.video').mousedown(function(){
$('#log').html('Mousedown!');
alert('mousedown');
/* This will track mousedown events in embed objects (not iframes), but not allow the click event to pass through to object. */
});
</script>
</body>
</html>
How can I track play counts for each of these videos?
Ryan, the only way to do this is to use the video sharing site's player api(s), as html and javascript have no native support for this.
To do this for youtube videos, you can check out the documentation here
To do this for vimeo videos, you can check out the documentation here
This works for Vimeo... Triggers a javascript alert on the "Play" event but there are a number of other events like "finished", "pause", "playProgress" (constantly updating while video is playing)... Uses Jquery
$(document).ready( function () {
var f = $('iframe'),
url = f.attr('src').split('?')[0],
status = $('.status');
// Listen for messages from the player
if (window.addEventListener){
window.addEventListener('message', onMessageReceived, false);
}
else {
window.attachEvent('onmessage', onMessageReceived, false);
}
// Handle messages received from the player
function onMessageReceived(e) {
var data = JSON.parse(e.data);
switch (data.event) {
case 'ready':
onReady();
break;
case 'play':
onPlay();
break;
}
}
// Call the API when a button is pressed
$('button').on('click', function() {
post($(this).text().toLowerCase());
});
// Helper function for sending a message to the player
function post(action, value) {
var data = { method: action };
if (value) {
data.value = value;
}
f[0].contentWindow.postMessage(JSON.stringify(data), url);
}
function onReady() {
status.text('ready');
post('addEventListener', 'play');
}
function onPlay() {
alert("Dude done clicked 'Play'");
}
});
How to append to textarea with PHP and then refresh the textarea?
THANK YOU
edit:
It should be server triggered from PHP code
The simplest approach would be to have a javascript function that polls the php script using ajax - say every 10 seconds. You could add a timestamp as a parameter to the php function so it only returns the latest log entries.
When the ajax call returns you can append the resulting text to your textarea using javascript.
I could fish out some sample code if you like?
So, here's an HTML file - it has a function to make an AJAX call to a script - log.php that returns some stuff (in this example it's a very simple line of text) and then append this to the text area.
When the script loads we set up a timer to fire every 1000 milliseconds (obviously change this according you your needs).
We've also got a "cancel updates" function and a "start updates".
So - put the html file and the php file (which you need to call log.php - or call it what you like and change the code) into the same directory on your web server and see what happens!.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var http = createRequestObject();
var updateInt=self.setInterval("updateLog()",1000);
function startAutoUpdate(){
if(updateInt==""){
updateInt=window.setInterval("updateLog()",1000)
}else{
stop_Int()
}
}
function stopAutoUpdate(){
if(updateInt!=""){
window.clearInterval(updateInt)
updateInt=""
}
}
function createRequestObject() {
var objAjax;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
objAjax = new ActiveXObject("Microsoft.XMLHTTP");
}else{
objAjax = new XMLHttpRequest();
}
return objAjax;
}
function updateLog(){
http.open('get','log.php');
http.onreadystatechange = updateNewContent;
http.send(null);
return false;
}
function updateNewContent(){
if(http.readyState == 4){
document.getElementById('log').innerHTML = document.getElementById('log').innerHTML + http.responseText;
}
}
</script>
</head>
<body>
<h2>Log</h2>
<textarea cols="80" rows="10" name="log" id="log"></textarea>
<span onclick="updateLog()">Update</span><br>
<span onclick="stopAutoUpdate()">Cancel Auto Update</span><br>
<span onclick="startAutoUpdate()">Start Auto Update</span><br>
</body>
</html>
Here's the php script (very simple)...
<?PHP
/* Log responder script
*
* When invoked this script returns log entries
* as this is a sample it just returns a couple of random items
*
*/
echo "Log Entry ".date("d/m/y h:i:s")."\n";
?>