Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Monday, April 29, 2013

How to Print a part of webpage using Javascript


<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
function printDiv()
{
   var divToPrint=document.getEelementById('areaToPrint');
  newWin= window.open("");
  newWin.document.write(divToPrint.outerHTML);
  newWin.print();
  newWin.close();
}
</script>

<div id="areaToPrint">
The text you want to print or the content you want to print
</div>
</div>

How to add a Bookmark to the Browser using Javascript


<div dir="ltr" style="text-align: left;" trbidi="on">
<script type="text/javascript">
function Add_Bookmark_Favorite(url,title)
{
 if (window.sidebar)
 { // Mozilla Firefox Bookmark
  //Make sure "Load this bookmark in the sidebar is deselected
  window.sidebar.addPanel(title, url,"");
  return false;
 }
 else if( window.external )
 { // IE Favorites
  window.external.AddFavorite( url, title);
  return false;
 }
 else if(window.opera && window.print)
 { // Opera Bookmark
  return !addToFav(url,title)
 }
}
</script>
<a href="" onclick="Add_Bookmark_Favorite('http://www.google.com/','Google')">Bookmark this link</a>

</div>

Limit the text area using Javascript

Wednesday, November 21, 2012

Javascript – get Url

window.location.href - get entire url
window.location.protocol - get protocol: "http" / "https"
window.location.host - get hostname, e.g: "www.g31zone.com"
window.location.pathname - get script name, e.g: "example/index.html"