iframe only loads on click - php

Is there a way to use jQuery to get an iframe to load on a click, i want this as is the iframe is hidden in a div that is not viewable until clicked, so the heavy majority of users will not be viewing the iframe, and i dont want the load time to be affected by the iframe.
This is one of the few things i've tried, the iframe does not load:
$(function() {
var emba=1;
var embget = 1;
$(".custemba").click(function(event) {
event.preventDefault(event);
if(emba == 1) {
emba = 2;
$('.custemb').slideDown();
if(embget == 2) {
$('.appendi').append('<iframe src="/player_i.php?aid=12" height="170px" width="100%" scrolling="no" frameborder="0"></iframe>');
embget = 2;
}
}
else if(emba == 2) {
emba = 1;
$('.custemb').slideUp();
}
});
});

Looks like
if(embget == 2)
should be
if(embget == 1)
And you don't need that extra event in
event.preventDefault();
Here's a simplified version:
var appendIFrame = true;
$(".custemba").click(function(event) {
event.preventDefault();
$('.custemb').slideToggle();
if(appendIFrame) {
$('.appendi').append('<iframe src="/player_i.php?aid=12" height="170px" width="100%" scrolling="no" frameborder="0"></iframe>');
appendIFrame = false;
}
});

The following works for me, a tad cleaner, creating the object before appending:
HTML:
<div>
Show iFrame
</div>
<div class="framebox"></div>​
JS:
var frame_loaded = false;
$(".showframe").click(function(event) {
event.preventDefault();
if (frame_loaded === false) {
var frame_element = $('<iframe>');
frame_element.attr({
src: "http://eatabagofdicks.com",
height: "170px",
width: "100%",
scrolling: "no",
frameborder: "0"
});
$(".framebox").append(frame_element);
frame_loaded = true;
}
$(".framebox").slideToggle();
});​

Related

Click back counter

Hello i have this code which works for redirect back
Redirect Users leaving your site - Javascript back button hack
<?php
$javascript = <<<DOC
<script>
var ref = document.referrer;
var siteurl = "YOUR URL HERE";//if you have www, then use www. http://www.yoursite.com
if (ref.indexOf(siteurl)!= -1){
}
else{
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/auth");
history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", function() {
if(location.hash === "#!/auth") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
location.replace("http://www.blackhatworld.com/");
},0);
}
}, false);
}(window, location));
}
</script>
DOC;
echo $javascript;
?>
I want to add it a counter that will only redirect after 3 clicks on back.
How to do it?
try this javascript code :
<button id="button">Click Back 3 Times </button>
<script>
var counter = 0;
$("#button").click(function () {
counter++;
if (counter == 3) {
window.history.back();
}
});
</script>
This code also works but i need to add the counter
this code which works for redirect back Redirect Users leaving your site - Javascript back button hack:
<script>
// managage back button click (and backspace)
var count = 0; // needed for safari
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("back", null, null);
window.onpopstate = function () {
history.pushState('back', null, null);
if(count == 1){window.location = 'http://google.co.il';}
};
}
}
setTimeout(function(){count = 1;},200);
</script>
Looking for a code to make redirect to page after clicking browser back button on the 3rd time... first 2 clicks should remain at the page

Using JQuery to change an image

I have a table where every other row is hidden. When I click an image, it will display the hidden row and hide all other rows. I'm able to show and hide the rows ok, but for some reason the image will not roll over.
<script type="text/javascript">
function toggleByID(id) {
$('.data-row-hidden').each(function(index) {
if ($(this).attr("id") == "row"+id) {
$(this).toggle(500);
$('#img'+id).attr("src", "images/toggle_expand.png");
}
else {
$(this).hide();
$('#img'+id).attr("src", "images/toggle_collapse.png");
}
});
}
</script>
Here is the code I'm using for the hidden row:
<tr id="<?='row'.$value['property_id']?>" class="data-row-hidden">
Here is the code I'm using to call the function:
<img id="<?='img'.$value['property_id']?>" src="images/toggle_collapse.png" border="0" height="20" width="20" onclick="javascript:toggleByID(<?=$value['property_id']?>)">
try this,
<script type="text/javascript">
function toggleByID(id) {
$('.data-row-hidden').each(function(index) {
var newImage = new Image();
if ($(this).attr("id") == "row"+id) {
$(this).toggle(500);
newImage.src = "images/toggle_expand.png";
}
else {
$(this).hide();
newImage.src = "images/toggle_collapse.png";
}
//cache busting
newImage.src = newImage.src + "&_=" + new Date().getTime();
$('#img'+id).attr("src", newImage.src);
});
}
</script>
Change your else condition to
else {
$(this).hide();
$('#img'+id).show();
$('#img'+id).attr("src", "images/toggle_collapse.png");
}

Javascript/jquery not working in IE8

I'm currently working on a website and it runs correctly in chrome but for some reason IE8 does not want to run any of the javascript/jquery scripts. Even when I call for an alert on page ready, it does not pop up. It is a little sloppy; I've included all of the css and jquery in the actual index.php file and was planning on cleaning it up eventually after I was a little farther along, but enough of my terrible excuses. I've read that a trailing comma after an item can make a website not function correctly in IE, but I cannot find one in my code. I am still learning so I am sure there are many things that could be corrected in my code as well. Sorry for how long it is. Essentially what happens is that all of the hidden divs just hang out and lay overtop one another, and none of the code executes.
<script type="text/javascript">
function video_pop(vimeo_link) {
var vimeo_applet = "";
$('.prompt_inner').text(vimeo_applet);
vimeo_applet = "<div>";
vimeo_applet += "<iframe src=\""+vimeo_link+"\" id=\"vimeo_link\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
vimeo_applet += "</div>";
$('.prompt_inner').append(vimeo_applet);
$('.prompt_box').css("margin-left", (-(($('.prompt_inner').width())/2)));
$('.prompt_box').css("visibility", "visible");
$('.prompt_background').css("visibility", "visible");
$('.prompt_box').animate({
opacity: '1'
}, 500);
$('.prompt_background').animate({
opacity: '.95'
}, 500);
}
//MAIN MENU FUNCTIONS
function directors() {
$('.menu').stop().fadeOut(1000).hide();
$('#directors').stop().fadeIn(1000);
$('#col_work').stop().fadeOut(1000).hide();
$('#slideshow_container').stop().fadeIn(1000);
}
function contact() {
$('.menu').stop().fadeOut(1000).hide();
$('#main_contact').stop().fadeIn(1000);
$('#col_work').stop().fadeOut(1000).hide();
$('#slideshow_container').stop().fadeIn(1000);
}
function login() {
$('.menu').stop().fadeOut(1000).hide();
$('#login').stop().fadeIn(1000);
$('#col_work').stop().fadeOut(1000).hide();
$('#slideshow_container').stop().fadeIn(1000);
}
function work() {
$('.menu').stop().fadeOut(1000).hide();
clearInterval(slideshow_int);
$('#slideshow_container').stop().fadeOut(1000).hide();
$('#col_work').stop().fadeIn(1000);
}
function showmenu() {
$('#back_button').stop().fadeOut(1000).hide();
$('#director_set').stop().fadeOut(1000).hide();
$('#holness').stop().hide();
$('#pryce').stop().hide();
$('#ntiri').stop().hide();
$('#quiroz').stop().hide();
$('#col_work').stop().hide();
$('#main_menu').stop().fadeIn(1000);
start_slideshow();
$('#slideshow_container').stop().fadeIn(1000);
}
//DIRECTOR FILES
function director(x) {
$('.menu').stop().fadeOut(1000);
$('#main_menu').stop().fadeOut(1000);
$('#col_work').stop().fadeOut(1000).hide();
clearInterval(slideshow_int);
$('#slideshow_container').stop().fadeOut(1000);
$('#back_button').stop().fadeIn(1000);
$('#director_set').stop().fadeIn(1000);
if (x==="1") {
$('#holness').stop().fadeIn(1000);
}
else if (x==="2") {
$('#pryce').stop().fadeIn(1000);
}
else if (x==="3") {
$('#ntiri').stop().fadeIn(1000);
}
else if (x==="4") {
$('#quiroz').stop().fadeIn(1000);
}
}
function start_slideshow() {
slideshow_int = setInterval(function() {
$('#slides > div:first')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slides');
}, 5000);
}
$(document).ready(function() {
//HIDE MENUS
$('.menu').hide();
$('#director_set').hide();
$('#back_button').hide();
$('#holness').stop().hide();
$('#pryce').stop().hide();
$('#ntiri').stop().hide();
$('#quiroz').stop().hide();
$('#col_work').stop().hide();
video_pop("<?php
$query = "SELECT * FROM global WHERE id=1";
$queryobj = mysql_query($query);
$result = mysql_fetch_array($queryobj);
echo $result['ovideo'] ?>");
$('.prompt_background').click(function() {
$('.prompt_box').animate({
opacity: '0'
}, 500, function() {
$('.prompt_box').css("visibility", "hidden");
});
$(this).animate({
opacity: '0'
}, 500, function() {
$(this).css("visibility", "hidden");
var vimeo_applet = "";
$('.prompt_inner').text(vimeo_applet);
});
});
//SLIDESHOW CONTROL
$('#slides > div:gt(0)').hide();
start_slideshow();
//WORK MOUSEOVER
<?php
$queryobj = mysql_query("SELECT * FROM global_thumbnails");
$total_global_thumbs = mysql_num_rows($queryobj);
for ($i=1; $i<=$total_global_thumbs; $i++) {
$queryobj = mysql_query("SELECT * FROM global_thumbnails WHERE position = {$i}");
$result = mysql_fetch_array($queryobj);
$global_still_title = strtoupper($result['title']);
echo "$('#global_stills img:eq(".($i-1).")').mouseover(function() {
$('#global_titles').text(\"{$global_still_title}\");
});
";
}
?>
$('#global_stills img').mouseout(function() {
$('#global_titles').text("");
});
});
</script>
i think instead of this
for ($i=1; $i<=$total_global_thumbs; $i++)
try this
for (var i=1; i<=$total_global_thumbs; i++)
Because Without "var" declarations it won't work in IE8 .
once i also faced the same problem. so after i did this it works for me :)
Try to put all the jQuery between $(document).ready(function() { ... });

PhP/HTML play button

I'm wanting to make my own small webpage, I've got a domain Saoo.eu
As you see there is a small play button in the corner witch plays a playlist. Is there anyway to have that playbutton on each page I'd add in the future without resetting every time the page changes?
Am I forced to use iFrames for that?
This is my player code
<button id="audioControl" style="width:30px;height:25px;"></button>
<audio id="aud" src="" autoplay autobuffer />
Script:
$(document).ready(function() {
$('#audioControl').html('II');
if(Modernizr.audio && Modernizr.audio.mp3) {
audio.setAttribute("src",'http://daokun.webs.com/play0.mp3');
} else if(Modernizr.audio && Modernizr.audio.wav) {
audio.setAttribute("src", 'http://daokun.webs.com/play0.ogg');
}
});
var audio = document.getElementById('aud'),
count = 0;
$('#audioControl').toggle(
function () {
audio.pause();
$('#audioControl').html('>');
},
function () {
audio.play();
$('#audioControl').html('II');
}
);
audio.addEventListener("ended", function() {
count++;
if(count == 4){count = 0;}
if(Modernizr.audio && Modernizr.audio.mp3) {
audio.setAttribute("src",'http://daokun.webs.com/play'+count+'.mp3');
} else if(Modernizr.audio && Modernizr.audio.wav) {
audio.setAttribute("src", 'http://daokun.webs.com/play'+count+'.ogg');
}
audio.load();
});

Google+ Button not appearing

Following is the code:-
<script type="text/javascript">
var timer = 150;
var currentWindow;
$(document).ready(function()
{
$("#creditme").button({
icons: { primary: "ui-icon-check" }
}).hide();
$("#viewad").button({
icons: { primary: "ui-icon-play" }
}).hide();
$("#progressbar").progressbar({value: 0}).hide();
var time;
var id;
var title;
var url;
$('.googlep-advertisement').bind('click', function()
{
id = $(this).attr('id');
title = $(this).text();
url = $('#yturl-'+id).text();
timer = $('#ytime-'+id).text();
$("#dialog-message").dialog({
modal: true,
width: 700,
title: title,
resizable: false,
draggable: false,
beforeClose: function() { clearAd(); }
});
if (!$("#progressbar").is(":visible") && !$("#creditme").is(":visible"))
{
$("#viewad").show();
}
});
$("#viewad").bind('click',function() {
$.get("googlep_credit.php" + '?start=' + id);
$("#viewad").hide();
$("#progressbar").progressbar('value', 0).show();
currentWindow = window.open(url, 'videoad', 'height=480,width=640', false);
window.blur();
window.focus();
progresscount(timer);
});
$("#creditme").click(function() {
$.get("googlep_credit.php" + '?id=' + id);
$("#creditme").hide();
$("#dialog-message").dialog('close');
$("#"+id).parent().parent('tr').fadeOut('slow');
});
function progresscount(time)
{
if(time == 0)
{
if(isWindowClosed() == true)
{
alert('You closed the popup before timer reached zero or you are using popup-blocking software.');
$("#dialog-message").dialog('close');
}
else
{
$("#creditme").html('<g:plusone callback="plusone_vote" href="'+url'"></g:plusone>');
$("#creditme").show();
}
$("#progressbar").hide();
}
else
{
time--;
$("#progressbar").progressbar('value', parseInt((timer - time) * 100 / timer));
setTimeout(function() { progresscount(time) }, 100);
}
}
});
function isWindowClosed()
{
if (!currentWindow || typeof currentWindow == 'undefined' || currentWindow && currentWindow.closed)
{
return true;
}
else
{
return false;
}
}
function clearAd()
{
}
</script>
<style>
.dialog-message {
}
</style>
<div id="dialog-message" class="dialog-message" title="View Video" style="display:none">
<p>
<center>
<button id="viewad" style="ui-helper-hidden">Click here to view the video</button>
<div id="progressbar"></div>
<button id="creditme" style="ui-helper-hidden">Test</button>
</center>
</p>
</div>
Nothing wrong with the code.
The problem is:-
http://dl.dropbox.com/u/14384295/70.jpeg
When checked with google chrome inspect element,
The code appears as
http://dl.dropbox.com/u/14384295/71.jpeg
Correctly working will appear as > http://dl.dropbox.com/u/14384295/72.jpeg
It seems that the code is not being converted by the google js which is in the portion. I am sorry if i have been confusing.
I may probably be doing the addition of 'url' var incorrectly
I'm pretty sure your problem lies in this line:
$("#creditme").html('<g:plusone callback="plusone_vote"></g:plusone>');
You are dynamically adding the <g:plusone> element after the Google +1 script has been run, so nothing happens.
To solve it, simply put the +1 markup in the html from the beginning so the +1 script can find it and render it, and only call $("#creditme").show(); when you need to show it.
<button id="creditme" style="ui-helper-hidden">
<g:plusone callback="plusone_vote"></g:plusone>
</button>
If you want to dynamically change the URL after page load, check out the examples from the Google documentation. It will allow you to load the button explicitly.

Categories