Wednesday, September 9, 2009

Dynamic Height of iframe Javascript

Set the Height of iframe Dynamically..

1] If iframe Source from same domain

Here is the Code Used for to set the Height of iFrame Using Javascript.
this code is working if source of iframe is from same domain.
same domain means the script execution page and iframe page source from same hosting server.

function resizeFrame(f) {
f.style.height = f.contentWindow.document.body.scrollHeight+'px';
}

and on iframe onload="resizeFrame(this)"

1] If iframe Source from different domain

// FrameManager.js -- Must be added in Hosting window
var FrameManager =
{
currentFrameId : '',
currentFrameHeight : 0,
lastFrameId : '',
lastFrameHeight : 0,
resizeTimerId : null,

init : function()
{
if (FrameManager.resizeTimerId == null)
{
FrameManager.resizeTimerId = window.setInterval(FrameManager.resizeFrames, 500);
}
},

resizeFrames : function()
{
FrameManager.retrieveFrameIdAndHeight();

if ((FrameManager.currentFrameId != FrameManager.lastFrameId) ||
(FrameManager.currentFrameHeight != FrameManager.lastFrameHeight))
{
var iframe = document.getElementById(FrameManager.currentFrameId.toString());

if (iframe == null) return;

iframe.style.height = FrameManager.currentFrameHeight.toString() + "px";

FrameManager.lastFrameId = FrameManager.currentFrameId;
FrameManager.lastFrameHeight = FrameManager.currentFrameHeight;
window.location.hash = '#';
}
},

retrieveFrameIdAndHeight : function()
{
if (window.location.hash.length == 0) return;

var hashValue = window.location.hash.substring(1);

if ((hashValue == null) || (hashValue.length == 0)) return;

var pairs = hashValue.split('&');

if ((pairs != null) && (pairs.length > 0))
{
for(var i = 0; i < style="color: rgb(0, 0, 255);">var pair = pairs[i].split('=');

if ((pair != null) && (pair.length > 0))
{
if (pair[0] == 'frameId')
{
if ((pair[1] != null) && (pair[1].length > 0))
{
FrameManager.currentFrameId = pair[1];
}
}
else if (pair[0] == 'height')
{
var height = parseInt(pair[1]);

if (!isNaN(height))
{
FrameManager.currentFrameHeight = height;
FrameManager.currentFrameHeight += 15;
}
}
}
}
}
},

registerFrame : function(frame)
{
var currentLocation = location.href;
var hashIndex = currentLocation.indexOf('#');

if (hashIndex > -1)
{
currentLocation = currentLocation.substring(0, hashIndex);
}

frame.contentWindow.location = frame.src + '?frameId=' + frame.id + '#' + currentLocation;
}
};

window.setTimeout(FrameManager.init, 300);


// Host.html-Where the Target iframe resides
iframe id="ifrSample1" scrolling="no" frameborder="0" src="Frame.html" style="margin:0px;width:330px;height:100px" onload="FrameManager.registerFrame(this)"


// Frame.js -- Must be added in iframe window
function publishHeight()
{
if (window.location.hash.length == 0) return;

var frameId = getFrameId();

if (frameId == '') return;

var actualHeight = getBodyHeight();
var currentHeight = getViewPortHeight();

if (Math.abs(actualHeight - currentHeight) > 15)
{
var hostUrl = window.location.hash.substring(1);

hostUrl += "#";
hostUrl += 'frameId=' + frameId;
hostUrl += '&';
hostUrl += 'height=' + actualHeight.toString();

window.top.location = hostUrl;
}
}

function getFrameId()
{
var qs = parseQueryString(window.location.href);
var frameId = qs["frameId"];

var hashIndex = frameId.indexOf('#');

if (hashIndex > -1)
{
frameId = frameId.substring(0, hashIndex);
}

return frameId;
}

function getBodyHeight()
{
var height;
var scrollHeight;
var offsetHeight;

if (document.height)
{
height = document.height;
}
else if (document.body)
{
if (document.body.scrollHeight)
{
height = scrollHeight = document.body.scrollHeight;
}
if (document.body.offsetHeight)
{
height = offsetHeight = document.body.offsetHeight;
}

if (scrollHeight && offsetHeight)
{
height = Math.max(scrollHeight, offsetHeight);
}
}

return height;
}

function getViewPortHeight()
{
var height = 0;

if (window.innerHeight)
{
height = window.innerHeight - 18;
}
else if ((document.documentElement) && (document.documentElement.clientHeight))
{
height = document.documentElement.clientHeight;
}
else if ((document.body) && (document.body.clientHeight))
{
height = document.body.clientHeight;
}

return height;
}

function parseQueryString(url)
{
url = new String(url);
var queryStringValues = new Object();
var querystring = url.substring(url.indexOf('frameId') , url.length);
var querystringSplit = querystring.split('&');

for (i = 0; i < style="color: rgb(0, 0, 255);">var pair = querystringSplit[i].split('=');
var name = pair[0];
var value = pair[1];

queryStringValues[name] = value;
}

return queryStringValues;
}

// Frame.html-Will reside in another domain
script type="text/javascript" src="Frame.js" script
window.onload = function(event)
{
window.setInterval(publishHeight, 300);
}

Please note That i got above code from google search...........and i remove the two bugs from that....and it is working fine............

if have any problem let me know.............vish.ideal@gmail.com
Thanks,
Vishnu

Tuesday, September 1, 2009

URL Rewriting Using .htacess file

URL Rewriting Using .htacess file
Our Aim is to
http://www.example.com/test/blog/var1/testFile.html
into dynamic URL
http://www.example.com/test/testFile.php?var1=var1&var2=testFile
using .htacess file


Create .htacess file in test directory

Now you directory structure is
www.example.com/test/
.htacess
testFile.php

In .htacess file write the code
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^blog/([^/]+)/([^/]+)\.html$ /test/testFile.php?var1=$1&var1=$2 [QSA]

Now in testFile.php your code will be there
If you type URL in Browser
http://www.example.com/test/blog /var1/testFile.html

it will execute on server as
http://www.example.com/test/testFile.php?var1=var1&var2=testFile

if you want todo external redirecting the just change the .htacess code
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^blog/([^/]+)/([^/]+)\.html$ /test/testFile.php?var1=$1&var1=$2 [R=301,L]


Friday, April 10, 2009

IE, Lightbox JS and security popup over SSL connection

A security popup occurring only in IE, "This page contains both secure and nonsecure items. Do you want to display the nonsecure items?".

Solution: Change the following line in lightbox.css:

#prevLink, #nextLink{ width: 49%; height: 100%;
background-image: url(data:image/gif;base64,AAAA);
/* Trick IE into showing hover */ display: block; }

to the following:

#prevLink, #nextLink{ width: 49%; height: 100%;
background-image: url(../images/blank.gif);
/* Trick IE into showing hover */ display: block; }

Add blank.gif in images directory of lightbox library

Monday, September 15, 2008

How to Change Runlevels (LINUX GURU)

Many people get confused when trying to boot in to a runlevel other than runlevel 5, for example runlevel 3, disabiling the GUI front end with which most users are familiar. Hopefully this howto will help answer the questions "How do I disable X" or "How do I boot without X" or even "How do I get to single user mode.

Runlevels

0 - halt (Do NOT set initdefault to this)
1 - Single user mode
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
3 - Full multiuser mode
4 - unused or Admin
5 - X11
6 - reboot (Do NOT set initdefault to this)


How to set the default run level 5

Open /etc/inittab to change your runlevel

On about line 18 you will see a line like the one shown below.
id:3initdefault:

change it to 5 as below

id:5:initdefault:
Save file and exit

Wednesday, July 30, 2008

Remove an element in a JavaScript Array

A Easy Way to remove element from array in a javascript.

e.g. var arr = {"one":"Ram","two":"Mangesh","three":"Vishnu"};

now we have remove the element whose value is "Mangesh" and key is "two"

delete arr['two'];

Thursday, June 26, 2008

Install Apache Tomcat 5.5.26 on Fedora Core 6

Install the JDK on Fedora


1] Download tomcat Binary Distribution from http://tomcat.apache.org/download-55.cgi

2] Unzip and copy it /usr/local/

You will see directory structure similar like this

/usr/local/apache-tomcat-5.5.26

3] Now to set the environment variable CATALINA_HOME, JAVA_HOME and add it also in PATH

Open file “/root/.bashrc”

Append following three line.

export JAVA_HOME="/usr/java/jdk1.6.0_06"

export PATH=$PATH:/usr/java/jdk1.6.0_06/bin

export CATALINA_HOME=/usr/local/apache-tomcat-5.5.26

4] Now Start the Tomcat

/usr/local/apache-tomcat-5.5.26/bin/catlina.sh start

5 ] run the following URL in Browser.

http://localhost:8080/


Tuesday, June 24, 2008

Install the SUN JDK 1.6.0_06 on Fedora Core 6

1] Download the SUN JDK 1.6. From the following link. Compatible for fedora

http://java.sun.com/javase/downloads/index.jsp

You will get binary something name as “jdk-6u6-linux-i586.bin”

3. Now change the permission of the downloaded file to 777 like this:

chmod 0777 jdk-6u6-linux-i586.bin

4. Then run it:


./jdk-6u6-linux-i586.bin

You will need to type yes to indicate your acceptance to their agreement and the installation will complete on its own. Unfortunately you are not yet done. Type java -version on the command line and you will see that it still points to the crappy old JVM from gcj (GNU compiler for JAVA).

This will extract binary and install the jdk 1.6.0_06

Now you will see something like directory structure

/usr/java/jdk1.6.0_06/

5. Now you need to find the actual location of your JDK installation and indicate to Fedora to accept your choice.

Type the following:
updatedb;locate javac |grep bin

You will see an entry like this:
/usr/java/jdk1.6.0_06/bin/javac

Here /usr/java/jdk1.6.0_06 is the actual JAVA_HOME for your machine. Note this as you will need it to run the future commands.

Now you need to run the alternatives command to instruct Fedora to recognize Sun’s JVM.
alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_06/bin/java 100
alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_06/bin/jar 100
alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_06/bin/javac 100

You can do this for other Java executables too, should you need them, following the same pattern.

Finally you should configure alternative to use Sun’s JVM as the default JVM. To do this type:

/usr/sbin/alternatives --config java

This will present you with at least 2 options. Choose the one for Sun’s JVM.

Similar way you can do that for jar and javac command

/usr/sbin/alternatives --config jar

/usr/sbin/alternatives --config javac

Now you are done configuring Fedora for the most part. Type java -version and you should see something like this:

java version "1.6.0_06"

Java(TM) SE Runtime Environment (build 1.6.0_06-b02)

Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

Note: This works for most part, except Tomcat.The default installation of Tomcat has been hardwired to use GCJ (GNU Compiler for JAVA).