Archive for category JavaScript
Create CSS Stylesheet and JavaScript for Print
Posted by admin in CSS, HTML, JavaScript on April 13th, 2009

CSS Stylesheet for Print
When we want to print out HTML page we need a lighter version of our HTML page. Basically, we don’t want to print the background images, background colors, advertisements and other things which are not relevant in printing. For this purpose, we need to specify a CSS stylesheet which browser use when we print our HTML page. We can also change the width and layout of our HTML page. We can specify our CSS stylesheet for print like this.
<head> /*External style sheets*/ <link rel="stylesheet" href="css/print.css" type="text/css" media="print" /> </head>
<head> /*Embedded style sheets*/ <style type="text/css" media="print"> .noprint { display:none; } </style> </head>
The important thing to note here is the media descriptor media=”print” which we are giving through media attribute. The browser knows using this media descriptor that this CSS stylesheet is defined to use at the time of print. We can define CSS stylesheet for SCREEN like this.
<head> /*External style sheets*/ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> </head>
<head> /*Embedded style sheets*/ <style type="text/css" media="screen"> .header { width:800px; height:200px; } </style> </head>
In the following example, I don’t want to print the “Print this Coupon” link in coupon. So, I have just added the class “noprint” and set the display property none in this class. Now, I will apply this class to all the elements which I don’t want to print. You can easily create other classes for different purpose like to change the background color of element in print.
<!--coupon.html--> <html> <head> <title>CSS stylesheet for Print</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> <link rel="stylesheet" href="css/print.css" type="text/css" media="print" /> </head> <body> <div class="coupon-mini"> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="146" align="left" valign="top"><div class='default-coupon'><img src='/sites/default/files/coupon_116_116.'></div></td> <td width="354" align="left" valign="top"> <h3 style="font-family: 'palatino linotype',palatino; line-height:18px; padding:6px 0 0 0; color:#0e549c; "> Divan Restaurant and Hookah Lounge, Alabama </h3> <div class='coupons-text1'><span>McDonald 20% Off.</span><p>McDonald 20% Off.</p></div><br /> <div style="clear:both;"></div> <div class="detail-basic1"> 3125 Piedmont Rd NE, Atlanta, Alabama<br> <strong> Phone Number :</strong> (404) 365-0410<br/> <strong> Pincode:</strong> 30305 <div class="openhr1"><strong> Opening Hours:</strong> 6:30 PM to 01:00 AM</div> <div class="web1"> <div class="lft1"><a href="#" class="about-web-link">http://www.divanatlanta.com</a></div> <div class="rght1"><a href="#" class="about-mail-link">ajay0878@yahoo.com</a></div> </div> </div> </td> </tr> </table> </div> <div class="print noprint"><a href="javascript:window.print();" class="coupon-print-link">Print this Coupon</a></div> </body> </html>
We have also added the window.print() function on Print this Coupon link. This function print the current windows content. We can also print our page through File->Print… menu. But this function is useful when the toolbar and menubar are disabled.
How call JavaScript function from FLASH
Posted by admin in Flash, JavaScript on April 8th, 2009
We can call the JavaScript function from FLASH application. I am showing here how we do that.
getURL("javascript:helloWorld();");
Here “getURL()” is the Flash ActionScript function. We have give the name of our JavaScript function with “javascript:” as prefix. This will call the “helloWorld()” function which we have defined in JavaScript.
<script type="text/javascript"> function helloWorld() { alert('Hello World'); } </script>
Also, add the following parameter to the OBJECT and EMBED tag:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="120"> <param name="movie" value="swf/myflash.swf" /> <param name="allowscriptaccess" value="always" /> <param name="wmode" value="transparent" /> <param name="menu" value="false" /> <embed height="120" width="150" allowscriptaccess="always" wmode="transparent" menu="false" src="swf/myflash.swf" type="application/x-shockwave-flash"/> </object>
allowscriptaccess let the Flash application to communicate with the HTML page hosting it. This is required because getURL() function can cause JavaScript to use the permissions of the HTML page, which can be different from the permissions of your Flash application. This has important implications for cross-domain security.
The valid values for allowscriptaccess are:
always permits scripting operations at all times.
never forbids all scripting operations.
samedomain permits scripting operations only if the Flash application is from the same domain as the HTML page.
The default value used by all HTML publish templates is samedomain.
How to use wmode as transparent for flash and what’s its use?
Posted by admin in Flash, JavaScript on March 14th, 2009
Sometime our embedded flash object comes over our websites dropdown menus or over other objects like light box, jQuery Boxy, fancybox etc.
We can solve this problem by changing the wmode of embed to transparent. By changing the wmode to transparent the flash object becomes transparent.
We can do it in following ways.
HTML:-
Add the following parameter to the OBJECT tag:
<param name=”wmode” value=”transparent”>Add the following parameter to the EMBED tag:
wmode=”transparent”
JavaScript:-
If you are using swfobject.js javascript file for embedding. Then do it like this.
<script type="text/javascript"> var obj = new SWFObject(”player.swf”,”ply”,”300″,”250″,”9″,”#FFFFFF”); obj.addParam(”wmode”,”transparent”); </script>
If you want to apply the wmode transparent to whole HTML page. You can do this way.
<script type="text/javascript"> for (var ems = document.embeds, i = 0, em; em = ems[i]; i++) { em.setAttribute(’wmode’, ‘transparent’); var nx = em.nextSibling, pn = em.parentNode; pn.removeChild(em); pn.insertBefore(em, nx); } </script>

