Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-16-2008, 10:25 AM
Casual Pligger
 
Join Date: Oct 2007
Posts: 81
Thanks: 16
Thanked 8 Times in 4 Posts
Make this site your homepage?

How to add a link/button so that when user clicks it the site becomes home page/starting page of his browser?
Reply With Quote
  #2 (permalink)  
Old 01-16-2008, 12:37 PM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 849
Thanks: 74
Thanked 49 Times in 45 Posts
Heres the javascript:

Code:
<script language="JavaScript">
function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(window.location.href);
}
</script>
put that in your <head>

html for the link:

Code:
<a href="javascript:setHome()">
Set Home Page</a>
put that anywhere you want the link to appear.

Geoserv.
Reply With Quote
The Following User Says Thank You to Geoserv For This Useful Post:
  #3 (permalink)  
Old 01-16-2008, 12:44 PM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 849
Thanks: 74
Thanked 49 Times in 45 Posts
This section of code could cause an issue if you use the link on a page otherthan your home page. This bookmarks the page the link is on, if you want to place it on all pages but have it bookmark only your home page, change it to:

Code:
<a href="javascript:setHome("http://www.yourdomainname.com")">
Set Home Page</a>
Geoserv
Reply With Quote
The Following User Says Thank You to Geoserv For This Useful Post:
  #4 (permalink)  
Old 01-17-2008, 04:13 AM
Casual Pligger
 
Join Date: Oct 2007
Posts: 81
Thanks: 16
Thanked 8 Times in 4 Posts
I put
Code:
<script language="JavaScript">
function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(window.location.href);
}
</script>
inside <head></head> of pligg.tpl file and

Code:
<a href="javascript:setHome("http://www.yourdomainname.com")">
Set Home Page</a>
at the beginning of header.tpl file of yget template. I am getting a blank page with the error:
Code:
Fatal error: TPL: [in yget/pligg.tpl line 49]: syntax error: document function does not exist (class.compiler.php, line 485) in E:\apachefriends\xampp\htdocs\pligg\class.template.php on line 923
How to fix it?
Reply With Quote
  #5 (permalink)  
Old 01-17-2008, 06:13 AM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 849
Thanks: 74
Thanked 49 Times in 45 Posts
Change:

Code:
<script language="JavaScript">
function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(window.location.href);
}
</script>
to:

Code:
{literal}<script language="JavaScript">
function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(window.location.href);
}
</script>{/literal}
Geoserv
Reply With Quote
The Following 2 Users Say Thank You to Geoserv For This Useful Post:
  #6 (permalink)  
Old 01-24-2008, 02:07 AM
Casual Pligger
 
Join Date: Oct 2007
Posts: 81
Thanks: 16
Thanked 8 Times in 4 Posts
{literal} was a life saver.

I slightly modified
Code:
<a href="javascript:setHome('http://www.yourdomainname.com')">
Set Home Page</a>
This code only works with IE.

Any idea about firefox or safari?
__________________
- Aneem
Reply With Quote
The Following User Says Thank You to animas For This Useful Post:
  #7 (permalink)  
Old 01-24-2008, 05:22 AM
Pligg Donor
 
Join Date: Sep 2007
Posts: 184
Thanks: 7
Thanked 37 Times in 26 Posts
As far as I know, there is no such thing as "setting the homepage" that works in Firefox. People have been looking for years on a solution that is cross browser compatible, but in the Mozilla forums, nobody has come up with a solution that I have found yet. There are only scripts that will allow you to add your site to your favorites or just bookmark it, such as this one: Dynamic Drive DHTML Scripts- Bookmark Site script

In all honesty, most users use IE 6 or 7 anyway. If the "add this site as homepage" is that important to you, then use the code you already have and leave the Firefox Guru's to do it manually. I do all that crap manually anyway, even if there is a "add this" link on the page, as I am so used to it. (Ha!)
Reply With Quote
The Following User Says Thank You to blaze For This Useful Post:
  #8 (permalink)  
Old 01-24-2008, 08:14 AM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 849
Thanks: 74
Thanked 49 Times in 45 Posts
Heres the best thing I can find, since there is no good solution for Firefox except having it load in the sidebar which is useless.

This script will do the bookmark is all browsers, in Firefox, it can't bookmark it but if the user is using Firefox when they click the link, a box will appear telling them to press ctrl + D.

I have it working on my website News Dots / Published Dots top right hand corner.

Add this file to your root:

add_bookmark.js

Code:
/* 
*  Copyright 2006-2007 Dynamic Site Solutions.
*  Free use of this script is permitted for non-commercial applications,
*  subject to the requirement that this comment block be kept and not be
*  altered.  The data and executable parts of the script may be changed
*  as needed.  Dynamic Site Solutions makes no warranty regarding fitness
*  of use or correct function of the script.  Terms for use of this script
*  in commercial applications may be negotiated; for this, or for other
*  questions, contact "license-info@dynamicsitesolutions.com".
*
*  Script by: Dynamic Site Solutions -- http://www.dynamicsitesolutions.com/
*  Last Updated: 2007-06-17
*/

//IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Konqueror 3, IE5/Mac, iCab 3

var addBookmarkObj = {
  linkText:'Bookmark This Page',
  addTextLink:function(parId){
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    a.appendChild(document.createTextNode(addBookmarkObj.linkText));
  },
  addImageLink:function(parId,imgPath){
    if(!imgPath || isEmpty(imgPath)) return;
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    var img = document.createElement('img');
    img.title = img.alt = addBookmarkObj.linkText;
    img.src = imgPath;
    a.appendChild(img);
  },
  makeLink:function(parId) {
    if(!document.getElementById || !document.createTextNode) return null;
    parId=((typeof(parId)=='string')&&!isEmpty(parId))
      ?parId:'addBookmarkContainer';
    var cont=document.getElementById(parId);
    if(!cont) return null;
    var a=document.createElement('a');
    a.href=location.href;
    if(window.opera) {
      a.rel='sidebar'; // this makes it work in Opera 7+
    } else {
      // this doesn't work in Opera 7+ if the link has an onclick handler,
      // so we only add it if the browser isn't Opera.
      a.onclick=function() {
        addBookmarkObj.exec(this.href,this.title);
        return false;
      }
    }
    a.title=document.title;
    return cont.appendChild(a);
  },
  exec:function(url, title) {
    // user agent sniffing is bad in general, but this is one of the times 
    // when it's really necessary
    var ua=navigator.userAgent.toLowerCase();
    var isKonq=(ua.indexOf('konqueror')!=-1);
    var isSafari=(ua.indexOf('webkit')!=-1);
    var isMac=(ua.indexOf('mac')!=-1);
    var buttonStr=isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        // IE4/Win generates an error when you
        // execute "typeof(window.external.AddFavorite)"
        // In IE7 the page must be from a web server, not directly from a local 
        // file system, otherwise, you will get a permission denied error.
        window.external.AddFavorite(url, title); // IE/Win
    } else if(isKonq) {
      alert('You need to press CTRL + B to bookmark our site.');
    } else if(window.opera) {
      void(0); // do nothing here (Opera 7+)
    } else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
      alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
      alert('You need to press Command/Cmd + D to bookmark our site.');    
    } else {
      alert('In order to bookmark this site you need to do so manually '+
        'through your browser.');
    }
  }
}

function isEmpty(s){return ((s=='')||/^\s*$/.test(s));}

function dss_addEvent(el,etype,fn) {
  if(el.addEventListener && (!window.opera || opera.version) &&
  (etype!='load')) {
    el.addEventListener(etype,fn,false);
  } else if(el.attachEvent) {
    el.attachEvent('on'+etype,fn);
  } else {
    if(typeof(fn) != "function") return;
    if(typeof(window.earlyNS4)=='undefined') {
      // to prevent this function from crashing Netscape versions before 4.02
      window.earlyNS4=((navigator.appName.toLowerCase()=='netscape')&&
      (parseFloat(navigator.appVersion)<4.02)&&document.layers);
    }
    if((typeof(el['on'+etype])=="function")&&!window.earlyNS4) {
      var tempFunc = el['on'+etype];
      el['on'+etype]=function(e){
        var a=tempFunc(e),b=fn(e);
        a=(typeof(a)=='undefined')?true:a;
        b=(typeof(b)=='undefined')?true:b;
        return (a&&b);
      }
    } else {
      el['on'+etype]=fn;
    }
  }
}

dss_addEvent(window,'load',addBookmarkObj.addTextLink);

// to make multiple links, do something like this:
/*
dss_addEvent(window,'load',function(){
  var f=addBookmarkObj.addTextLink;
  f();
  f('otherContainerID');
});
*/

// below is an example of how to make an image link with this
// the first parameter is the ID. If you pass an empty string it defaults to
// 'addBookmarkContainer'.
/*
dss_addEvent(window,'load',function(){
  addBookmarkObj.addImageLink('','/');
});
*/

Place this link anywhere on your page:


Quote:
<p id="addBookmarkContainer"></p><p id="addBookmarkContainer"></p>
Looks like the best option right now.

Geoserv.
Reply With Quote
  #9 (permalink)  
Old 01-24-2008, 08:18 AM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 849
Thanks: 74
Thanked 49 Times in 45 Posts
As a followup, you can use:

Quote:
<p id="addBookmarkContainer"></p><p id="addBookmarkContainer"></p>
or if you don't want it to drop to the next line, you can use:

Quote:
<a id="addBookmarkContainer"></a>
I changed my to the latter.

Geoserv

Last edited by Geoserv; 01-24-2008 at 10:06 AM..
Reply With Quote
  #10 (permalink)  
Old 01-24-2008, 08:32 AM
Pligg Donor
 
Join Date: Sep 2007
Posts: 184
Thanks: 7
Thanked 37 Times in 26 Posts
Hey Geoserv... you may want to look at the solution I provided. Dynamic Drive DHTML Scripts- Bookmark Site script

It seems to do the same thing your solution does, with the exception that you don't need to press ctrl+d to bookmark in firefox. It doesn't add the bookmark into the sidebar for me either (FF 2.0), just adds it to your bookmarks.
Reply With Quote
Reply

Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
Some ideas to build a Pligg site Divisive Cotton Off-topic 20 06-03-2008 04:09 PM
SEO (Search Engine Optimization) Yankidank Wiki Articles 23 12-02-2007 12:27 PM


Search Engine Friendly URLs by vBSEO 3.2.0