SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript powered button for FF

    I'm trying to make an "Add This Page" button that can be used in FF, along the lines of the del.icio.us one. So far the javascript I've come up with is...

    javascript:var a=function(){if(!window.open('http://www.waste-some-time.com/toolbaradder.php?title=document.title&url=document.URL','Add This Link','toolbar=0,status=0,resizable=0,width=626,height=436'))document.location.href='http://www.waste-some-time.com/toolbaradder.php'};

    But...it doesn't seem to do anything. I'm a bit of a javascript n00b so please go easy on me!
    Thanks
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    document.location is the same as document.URL but is deprecated - you would need window.location.

    I assume you mean for people to put the link on their page. Where would they be putting this javascript? You can't expect people to put it in their <head>, attach an event listener to a link they have to create and on top of that tolerate popups. If you intend the popup to appear when the page loads, that's even worse and will likely be stopped by most popup blockers.

    In this instance I think a bit of tag soup is better than a popup. This means use of document.write, so people just put this on their site in the body where they want the link to appear:
    Code:
    <script type="text/javascript">document.write('<a href="http://www.waste-some-time.com/toolbaradder.php?title='+document.title+'&amp;url='+window.location);</script>
    However, if you want to cater for those who wouldn't want additional junk in their external JS files and won't put any <script> tags in their body (like me), I think you could just do this with PHP, using the referrer in the header from the link (yes, I know not all user agents send referrer headers, but if this is the unlikely case you can point it out and make the person type the stuff out manually). Then your script downloads the page in question and you parse it, looking for the <title>, and you extract the title text. Should be fairly simple, but it would require use of the cURL extension for PHP which isn't installed by default.

  3. #3
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The intended location of the code is actually in a firefox button on the bookmarks toolbar, with the intended result of a click being to open a popup window, so concerns about what other site owners would put into their pages don't matter.
    The basic function needed is just to open a popup window containing a certain page, with url parameters containing the title and location of the page the user was on when the button was pressed.
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  4. #4
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After some more experimenting I've got this code to do basically what I want, with one problem. It works perfectly in IE, but in FF, the new pop-up window is below the original window, not above it as I would desire. Any ideas about how to fix this?

    My code:
    javascript:var a={window.open('http://www.waste-some-time.com/share.php?link='+document.location+'&title='+document.title,'sharer','toolbar=0,status=0,resizable=0,width=626,height=436')

    Looking at some examples of script that does this, it looks like I might have to define a as a function, then use this bit of code...

    if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0)

    but I don't really understand what it does, and can't get it to work with my code above.
    Any help much appreciated,

    Alex
    "The proper function of man is to live - not to exist."
    Get a Free TomTom



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •