Fancy Box Body onLoad not working - anyone know why?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Fancy Box Body onLoad not working - anyone know why?

Post by simonmlewis »

Code: Select all

if ($paid == "y")
{
echo "<script>
$(document).ready(function(){
 $(\"#addop\").fancybox({
  'width': 640,  //or whatever
  'height': 400.
  'type': 'iframe' // see this?
 });
});
</script>
<body onload=\"$('#addop').trigger('click');\">";
}
The addop is set in a DIV further down, but my question is can you use SCRIPT like this within an 'echo' in the way I have done it?

It has to be like this, so it runs only when there is something in the $paid variable.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Fancy Box Body onLoad not working - anyone know why?

Post by yacahuma »

I am not sure what do you want but take a look at this http://defunkt.io/facebox/
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Fancy Box Body onLoad not working - anyone know why?

Post by simonmlewis »

Thanks I will have a play and see how I get on.
I've already written my scripts. The problem I often have is if the script is being used in one part of the page, such as admin.php, then test.inc where the same script is entered, will not work.

For example: At the top in admin.php I have "Operators" shown with an "Add" link. The 'Add' link opens a 'fancybox' with a form. Nice and neat.
However, If the user has no operators, I want the operators.inc page to show the Add link too (a nice big friendly button to start at ), but it will not work. It's identical code.

I've even used identical code, but changed the #name in case it was getting confused. Still no go.

Very annoying.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Fancy Box Body onLoad not working - anyone know why?

Post by simonmlewis »

Hi.
I've not got this working without any of the flaw of the 'fancybox'. Many thanks.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Fancy Box Body onLoad not working - anyone know why?

Post by simonmlewis »

How do you use this part of it?

[text]Attach It onLoad

While calling facebox() on any anchor tag will do the trick, it's easier to give your Faceboxy links a rel="facebox" and hit them all onLoad.
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox()
})
[/text]

Do you put that code in a <script></script> tag? As that doesn't work for me.
It would be useful to have this work, as one particular page does need to highlight something important to the user, and this would be a smart way to do it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply