Archive for the ‘Dynamic Web Pages’ Category

How to Include a Page from another Website

Monday, February 9th, 2009
  • Include a Page from another Website

In this tutorial discover how to Include a Page from another website without getting the nasty Warning – URL file access is disabled in the server configuration

  • URL file Access Warning

This is the big problem to do because you usually get this warning – URL file access is disabled in the server configuration. What it means is you can”t use a server side file [such as asp, php] from another server inside a server side file. So using the PHP include like this <?php include (”http://someothersite.com/index.php”); ?> will fail and give you the dreaded Warning – URL file access is disabled in the server . However, it works perfectly for a file stored on the same server!

  • cURL is the Cure!

Instead of the usual PHP Include, use this code instead to Include a Page from another website:<?php$curl = curl_init();curl_setopt($curl, CURLOPT_URL, "http://someothersite.com/index.php");curl_exec($curl);curl_close($curl);?>

  • Preserve your SEO

The beauty of this method is that your page will still be crawled by the search engines as usual, whereas solving this problem with frames leaves a lot of doubt as to whether the content is crawled and cached!

  • Fast updating

A side effect of using this method is that you can keep one file of, say, current events, on your server, and include it in many other websites.  Then all you need to do is update one file and every other site will display the updated information automatically – ”aint that sweet?”, How to Include a Page from another Website

How to Tame IE6 Hover Problem

Sunday, August 31st, 2008

How to Tame IE6 Hover Problem

Suppose you want to make a pop-up tool-tip with CSS and you get it all done, but your tool-tip won’t work in Internet Explorer because of the IE6 Hover Problem. You can solve this with Java Script, but it takes quite a bit of code, and it isn’t really necessary.  There is a way to make IE6 hover work just using CSS and one simple trick.

  • Use Tool-tips ??

Maybe you want to provide an explanation or some other info when the user hovers the mouse over a word in your text like this. You can make a tool tip appear by putting your explanatory text in the ‘title’ field of an anchor.  The problem with that is that you can’t style it, and by default it disappears after 5 seconds.  Useless for long explanations because you don’t get time to read it before it vanishes.

  • Pure CSS Pop-ups

You can have  nicely styled pop-upsYour beautifully styled Tool Tip pop-up window looks like this.You can add code to it (E.G., <p>), style it how you like, and generally stamp your imprint on it to reflect your site or your personality. that fit your theme and are cross browser compatible using just style statements – no Scripts!  Add the following code to your style sheet or style statements in the header:

/* Pop up styles  */

a.ref   {
position: relative;
}
a span   {
border: 1px solid #700;
padding: 4px;
visibility: hidden;
position: absolute;
top: 30px;
left: -20px;
color: #900;
background: #ffd;
width: 250px;
}
a:hover   {
background-color:white; /* Trigger for IE6  */
}
a:hover span, a:active span, a:visited:hover span    {
visibility: visible;
text-decoration: none;
}

  • The Secret

Note this code: a:hover   { background-color:white;  } /* Trigger for IE6  */ Because IE6 will not action a hover call for anything other than the <a> anchor itself, you need to trigger the hover event by calling a straight hover action like this a:hover {something}, then it will read the rest of the hover code and action it.  In this case I have used a <span> to make the tool-tip hover, but you can apply this to  <img>; or whatever…..

  • The Code:

The Page code looks like this:
<a href=”#” class=”ref”>anchor text here<span> Pop-up Text contained in the span statement</span></a>

Hover this to see it work anchor text herePop-up Text contained in the span statement and beat the IE6 Hover Problem once and for all.

  • Tip:

If you are doing this in WordPress, use the ‘HTML’ tab, not the ‘Visual’ Tab for editing it, ’cause WP makes a right ‘Dog’s Breakfast’ of the embedded code if you save it in Visual.

Dynamic IFrames

Monday, December 24th, 2007

An easy way to build a dynamic page is to use an iFrame as a holder and pop various other content pages into it. The problem with that is that iFrames are rigidly specified by size and your dynamic input might not fit.

Here is an easy solution. Take advantage of the power of the document.getElementByID Javascript function to retrieve the size of the document you want to insert, then use the same script to write it’s height to the frame.

Here is the Script to find and set the size:

<script language=”JavaScript”>
<!–
function findHeight()
{
//measure height of page to be included
var ifr_height= document.getElementById(’iframe_id’).contentWindow.document.body.scrollHeight;
//change height of container
document.getElementById(’iframe_id’).height= ifr_height;
}
//–>
</script>

Just paste that into your document head code and then specify the iFrame like this:

<iframe id=”iframe_id” src=”text.htm” scrolling=”no”
style=”
width: 780px;
height:1;
border: 4px inset #f00; ”
onLoad="findHeight();" >

You will need an “iframe enabled browser to render this page.
</iframe>

Check it out here : iframe.htm

Tested on IEx, FireFox, and Opera.

Re-Sizable Pages

Wednesday, October 3rd, 2007

A major problem with re-sizable pages is that some browsers render text, etc, at different pixel widths, and the page you spent all that time on to look perfect turns to rat-shit when rendered at a different screen resolution, or by a different browser.

Use a Constant
The sure cure is simply to use the same unit for both fonts and containers. Use ems for page (or div) widths as well as font size and whatever pixel width the browser uses will translate equally to both the fonts and the boxes containing them.

Set the Ratio of font size like this:
BODY {font-size: 62.5%; } // sets default font size at 10px
Kludge IExplorer:
table {font-size: 1em; border: 0px; padding: 0px;} // workaround required to suit IEx
Set Actual Font-sizes within the page with declarations:
.p12 { font-size: 1.2em; } //will give font size of 12px
.p14 { font-size: 1.4em; } //will give font size of 14px
Set Box Size in ems:
.box { width: 50em; } //width of containing box (Main page content) sized in ems.

A page set up like this will keep its integrity whatever text size or screen resolution the viewer chooses.

Animated Div's with a JavaScript Tween

Thursday, May 17th, 2007

Animated Div’s with a JavaScript Tween

Have you ever wanted to put some movement on your pages, but haven’t liked to clutter up your site with Flash movies?

•  Working Example:   Here is an example of tweening Div’s to slide in from the left See it working here

•  The Tween Script:  Here is how you can do it with the tween.js script (from Phillippe Maegerman). N.B. you can paste the MM Show Hide Script into this file as well.

•  What to Do   Put the tween.js script file in your site root folder and call it from the page that needs it <script type=”text/javascript” src=”tween.js”></script>

Call the appropriate script function with an onclick event in your menu link, like this;
onclick=”t1 = new Tween(document.getElementById(’div1‘).style, ‘left’,Tween.regularEaseOut,-700,200,.8,’px’); t1.start();
where div1 is the ID of the Div you want to animate
These numbers mean the div starts at -700(off the page) and moves right to 200px from the left margin, and takes .8 seconds to do it.

•  Next:   Define the Div in your CSS with width and height attributes and set the visibility of Div’s 2 – 6 to hidden. Make it become visible when the link is clicked with another onclick function like this:
MM_showHideLayers(’div1′,”,’show’,'div2′,”,’hide’,'div3′,”,’hide’,'div4′,”, ‘hide’,'div5′,”,’hide’,'div6′,”,’hide’);

•  Result:  Using the above code you can have 6 divs sliding happily on and off the page with a JavaScript that uses only 9kb of bandwidth – Magic!!

•  SEO Friendly:   The most important advantage of this method is that your page is almost totally Search Engine Friendly. None of the content is hidden as it is in flash movies, you can put your keyword laden content at the top of the page where it will be most effective for SEO and it will still appear exactly as you want it with your CSS styling. In the Example site above there are six animated pages and the whole lot adds up to less bandwidth than a moderately sized SWF file would need.

O.K., so there is a SWF movie on the example page, but that was the clients idea, not mine, and my comments are still valid.

•  Show/Hide the Divs:   Below is the Show Hide script: (Note: Don’t use a version earlier than v3.0, or it won’t work in Firefox)

function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i< (args.length-2); i+=3)
if ((obj=document.getElementById(args[i]))!=null) {
v=args[i+2];
if (obj.style) {
obj=obj.style;
v=(v=='show')?'visible':(v='hide')?'hidden':v;
}
obj.visibility=v;
}
}

•  All Done:   So there you go, a bandwidth-saving solution with a hi-tech look and result that gives you animated div’s with a JavaScript Tween.

Tables Vs CSS

Sunday, March 4th, 2007

I have read a lot of opinion on this subject, and have decided that I will use tables where applicable because they are really the best solution.

The root of this discussion ought to be focused around the very simple thesis that HTML is for Layout, and CSS is for Presentation.

This is the premise that CSS was conceived from and should be the decider in cases of doubt. If that is your starting point, then it is nonsense to attempt to lay out tabular data using pure CSS.

The most cogent argument for me is that there is less code to be written if you use tables – you might think that it is quicker to write a couple of DIV’s than to set out a table, but if you take into account the “cross-browser” code and “hacks” that needs to be built into your CSS to make the layout bullet-proof, then it is much simpler to use a table.

Example – To make a “liquid layout” 2 or 3 column standard page that will resize to suit any browser or viewport requires some quite technical CSS plus the attendant Java browser “sniffers” to make it a reliable page – and there is also the likelihood that the “hacks” you need to make it cross-browser compatible could fall over when the next generation of browsers appear. But build that same page with DIVs for header and footer and a 3 cell table to hold the centre columns, and the code is very short and simple and will render perfectly in any browser.

The 2 or 3 center columns are really TABULAR in nature, so it makes sense to use a table, and there are a couple of distinct advantages – like, for instance, the background color of the TD cells will automatically extend to the footer; v-align works properly in TDs; unpredictable things like FLOAT and CLEAR are unnecessary; and TDs automatically extend to accommodate variable data sizes.

I have tried various different techniques for coding liquid layout 2/3 column pages with pure CSS, but have not found a method that is both mean on bandwidth and cross-browser reliable. If anyone does know of such a method – please post a link to it.

I believe it is now imperative to make our pages resizable. The days when “everyone who mattered” used the same size 800×600px screen are long gone. I refuse to scroll sideways to read data and immediately abandon any website that has a page that won’t fit into my normal viewport (as defined by the browser window). Vast numbers of users now have broadband, big screens, and extended desk-tops, but parallel to that there are millions of users using laptops and other machines with restricted desk top space. To code up pages that require a 1280px plus screen is arrogant as well as being stupid – stupid, because you are willfully alienating a significant portion of your potential users.

The task of writing bullet-proof code is getting harder every day; harder because we now have to code for a wider range of browsers, and harder because we have such a fascinating lot of new style effects and tricks available for site design. It makes a lot of sense to use a simple, reliable, old table to control the page content layout, and to reserve CSS for what it does very well and was designed for; i.e., cascading styles down thru your sites pages. I also think it makes a site-wide re-vamp much easier if you don’t have to worry about the layout getting snarled up every time you edit your style sheets.

Dynamic Div's

Tuesday, February 20th, 2007

I’ve been trying for some time to come to grips with the concept of dynamically rendering pages so that bits of the content change without doing a refresh or rewrite.

There are a number of approaches to this with the obvious one being php. However a lot of coders find this whole php thing to be a bit intimidating, and want a way to make things happen without going down the road of learning that whole new language.

I started out working with iFrames and this is a brillant way to insert live updates and video and stuff into a page; but there are some frustrating limitations. Like for instance your iFrame stays the same size no matter what you squirt into it! Consider an Amazon aStore: the front page is about 600px high, but the actual shop pages are 1000px or more so either this pops up the dreaded scroll bars in your frame or else you have masses of white space.

I have found a way to make what I call Dynamic Divs – I.E., they expand or contract to fit the content linked to. This means you can have a fixed page with a block(<div>) of optional content that exactly fits the linked page.

It is an interesting hybrid mix of php, html and Javascript, but no coding skills are needed. Just copy’n'paste the code.

You need to name the file with a .php suffix to get the “php includes” to work, but it is basically simple html. The trick is to load the required page into a (not visible) storage div, extract it’s content into a variable with a little JavaScript, then write it into the div with the “document.getElementById(”alayer”).innerHTML” call. This reads the (hidden) file and writes it to the Dynamic Div.

See a demo of the technique here. Roll over the top links to see the Dynamic Div in action

Here are the four elements that make this work.
1. divs to hold the page to be inserted
2. Javascript to read the data
3. OnMouseover code to insert the content.
4. An ID’d div to insert the new content into.

1. The “storage boxes” look like this:
<div id=”bin1″ class=”bins”><?php include(’demo1.htm’) ?></div>
They have an ID and they need a style class set to display: none; so they are invisible, and there is a php include to load the file to be stored.

2. The Script to “read” the content into the variable looks like this:
<script language=’JavaScript’>
$con1 = document.getElementById(”bin1″).innerHTML;
$con2 = document.getElementById(”bin2″).innerHTML;
</script>
The script gets the “innerHTML” content of the Element “bin1″ and stores it in the variable $con1, and so on.

3. The content can then be written to the page with an onMouseOver call like this:
onmouseover=’document.getElementById(”alayer”).innerHTML=$con1;

4. A Div (ID=aLayer) to receive the content:
<div id=”alayer” style=”width: 750px; background-color:#ffd; “><?php include(’demo0.htm’); ?></div>

Notes:

This technique works best on pages with plain text or simple html. If you load a page with SSI in it, it will fail, because it is not on the server anymore, thus the script can’t work inside a client side page. An embedded PHP include, for instance, can’t work after it has left the server.

Be aware that what you are doing here is nesting complete web pages inside each other. This can have some quite exciting results – for instance if you have style classes in one page, they may conflict with another.
This trick is ideal to dynamically change text and graphic content inside a box(div), but without doing a page refresh or re-writing the page.