<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CrankBerry Blog &#187; HTML</title>
	<atom:link href="http://www.crankberryblog.com/category/scripts-and-programming/html-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crankberryblog.com</link>
	<description>Sharing ideas on web design, development and the internet economy</description>
	<lastBuildDate>Thu, 22 Apr 2010 21:46:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>In page popup with faded background &#8211; in PHP</title>
		<link>http://www.crankberryblog.com/2009/in-page-popup-with-faded-background-in-php</link>
		<comments>http://www.crankberryblog.com/2009/in-page-popup-with-faded-background-in-php#comments</comments>
		<pubDate>Tue, 20 Oct 2009 23:12:52 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=232</guid>
		<description><![CDATA[Sometimes you may be required to have popup windows on your website. They're obtrusive and hard to style with your site, in summary - nasty. What I've seen is other websites fade out their background and have an in page popup. I came up with a script that does the same thing in PHP and it looks exactly like the image below. Jump to the next page for the script.

<img src="http://www.crankberryblog.com/images/in-page-pop-up.jpg" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes you may be required to have popup windows on your website. They&#039;re obtrusive and hard to style with your site, in summary &#8211; nasty. What I&#039;ve seen is other websites fade out their background and have an in page popup. I came up with a script that does the same thing in PHP.</p>
<p>Now the code involves multiple parts so bare with me here. Either way your end product will look like the image below.</p>
<p><img src="http://www.crankberryblog.com/images/in-page-pop-up.jpg" /></p>
<p>Lets start with the CSS here. Just copy and paste this into your CSS file or HTML.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;style type=&quot;text/css&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; html {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 100%; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; .fade_container {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min-height: 100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: absolute;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z-index: 100000;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; overflow: hidden;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; .fade {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min-height: 100%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background: #000;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: absolute;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z-index: 110000;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; overflow: hidden;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; .popup {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, Helvetica, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 10px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 4px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: absolute;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 50%;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z-index: 150000;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; .popup_close {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, Helvetica, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 9px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-bottom: 5px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background: #CCC;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text-align: right;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; .popup_close a:link, .popup_close a:visited, .popup_close a:hover, .popup_close a:active {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #333;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text-decoration: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&lt;/style&gt;</div>
<p>There&#039;s really no need to edit anything unless you want to change the font and stuff, the colors will be modified later. The next part you have to add this code <strong>right after</strong> your &lt;body&gt; tag.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span></p>
<p><span class="co1">//In Page Popup Box with Faded Background by Jerry Low @crankberryblog.com</span><br />
<span class="co1">//Find other useful scripts at the Crankberry Blog</span></p>
<p><span class="co1">//SETTINGS</span><br />
<span class="re0">$fade_amount</span> = <span class="nu0">60</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//In Percentage</span><br />
<span class="re0">$box_width</span> = <span class="nu0">400</span>;<br />
<span class="re0">$box_background</span> = <span class="st0">&#039;FFFFFF&#039;</span>;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Hex Color</span><br />
<span class="re0">$box_border_width</span> = <span class="nu0">1</span>;<br />
<span class="re0">$box_border_color</span> = <span class="st0">&#039;999999&#039;</span>;&nbsp; &nbsp;<span class="co1">//Hex Color</span><br />
<span class="re0">$close_box</span> = <span class="nu0">1</span>;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Do You Want The Close Bar on Top 1 = Yes, 0 = No</span><br />
<span class="re0">$extension</span> = <span class="st0">&quot;&quot;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Other Variables that maybe needed, page number etc.</span></p>
<p>
<span class="co1">//Begin Popup Box</span><br />
<span class="re0">$left_margin</span> = <span class="nu0">0</span> &#8211; <span class="br0">&#40;</span><span class="re0">$box_width</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
<span class="re0">$page_url</span> = <a href="http://www.php.net/basename"><span class="kw3">basename</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#039;PHP_SELF&#039;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$extension</span>!=<span class="st0">&quot;&quot;</span><span class="br0">&#41;</span> <span class="re0">$page_url</span> .= <span class="st0">&#039;?&#039;</span> . <span class="re0">$extension</span>;</p>
<p><span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;popup&#039;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;div class=&quot;popup&quot; style=&quot;width:&#039;</span>.<span class="re0">$box_width</span>.<span class="st0">&#039;px; background: #&#039;</span>.<span class="re0">$box_background</span>.<span class="st0">&#039;; &nbsp;margin-left:&#039;</span>.<span class="re0">$left_margin</span>.<span class="st0">&#039;px;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$box_border_width</span>&gt;<span class="nu0">1</span><span class="br0">&#41;</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039; border: &#039;</span>.<span class="re0">$box_border_width</span>.<span class="st0">&#039;px solid #&#039;</span>.<span class="re0">$box_border_color</span>.<span class="st0">&#039;;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&quot;&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Close Box</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$close_box</span>===<span class="nu0">1</span><span class="br0">&#41;</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;div class=&quot;popup_close&quot;&gt;&lt;a href=&quot;&#039;</span>.<span class="re0">$page_url</span>.<span class="st0">&#039;&quot;&gt;Close (x)&lt;/a&gt;&lt;/div&gt;&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;!&#8211; START YOUR POPUP CONTENT HERE &#8211;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="me1">Popup</span> content goes in here!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;!&#8211; <a href="http://www.php.net/end"><span class="kw3">END</span></a> OF YOUR POPUP CONTENT HERE &#8211;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">&lt;?php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;fade&quot; onclick=&quot;location.replace(<span class="es0">\&#039;</span>&#039;</span>.<span class="re0">$page_url</span>.<span class="st0">&#039;<span class="es0">\&#039;</span>);&quot; style=&quot;opacity: 0.&#039;</span>.<span class="re0">$fade_amount</span>.<span class="st0">&#039;; &nbsp;-moz-opacity: 0.&#039;</span>.<span class="re0">$fade_amount</span>.<span class="st0">&#039;;filter: alpha(opacity: &#039;</span>.<span class="re0">$fade_amount</span>.<span class="st0">&#039;);&quot;&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;fade_container&quot;&gt;&#039;</span>;</p>
<p><span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></div>
<p>Looking at the top part of what you just added, the setting are at the top. Just configure it to what ever you like. </p>
<p>The Content</p>
<p>The content of your popup box goes in between the HTML comment tag in the code above. Exactly where I wrote: Popup content goes in here!</p>
<div class="dean_ch" style="white-space: wrap;">&lt;!&#8211; START YOUR POPUP CONTENT HERE &#8211;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
Popup content goes in here!<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&lt;!&#8211; END OF YOUR POPUP CONTENT HERE &#8211;&gt;<br />
&nbsp;</div>
<p>Next you need the trigger to activate the popup. Something like this:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;a href=<span class="st0">&quot;?popup=1&lt;?php if ($extension!=&#034;) echo &#039;&amp;&#039; . $extension; ?&gt;&quot;</span>&gt;Activated Box&lt;/a&gt;</div>
<p>To finish off the code you will need to add a &lt;/div&gt; tag just before the &lt;/body&gt; closing tag. Like so:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;/div&gt;&lt;/body&gt;</div>
<p>That&#039;s it and all you need to have your own in page with faded background popup window. Wasn&#039;t that just simple?</p>
<p><strong>Advance Configuration</strong></p>
<p>Now if your pages require other variables to be passed through the URL I noticed that the popup will intrude on that. So I have an extension variable where you can attach other variables to and they will be kept. The variable is in the setting part of the code. Example of attaching some variables.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$extension</span> = <span class="st0">&quot;&quot;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Other Variables that maybe needed, page number etc.</span><br />
<span class="re0">$extension</span> = <span class="st0">&#039;p=3&amp;sort=2&amp;id=214423&#039;</span>;<br />
&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2009/in-page-popup-with-faded-background-in-php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
