Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    showing div + add to favorites

    Hello I want to add an 'add to favorites' link on my website, since those links only work with javascript I want to hide the link for visitors with javascript disabled. I've came up with the following html and javascript:

    -------- html
    <div id="dhtmlEl" style="visibility: hidden;>
    <a class='green' href="javascript:bookmarksite('MSNEMO','http://www.msnemo.com');">Click here to bookmark msnemo</a></center><br><br>
    </div>
    --------



    -------- javascript
    <script type="text/javascript">
    <!--
    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';

    var detect = navigator.userAgent.toLowerCase();
    var browser,thestring;

    function bookmarksite(title, url){
    if(checkIt('msie'))
    {
    window.external.AddFavorite(url, title);
    }
    else if(checkIt('firefox'))
    {
    window.sidebar.addPanel(title, url, "")
    }
    else if(checkIt('netscape'))
    {
    document.write("press CTRL + D to bookmark our site.");
    }
    else if(checkIt('opera'))
    {
    document.write("press CTRL + T to bookmark our site.");
    }
    else
    { }

    }

    function checkIt(string)
    {
    place = detect.indexOf(string) + 1;
    thestring = string;
    return place;
    }
    //-->
    </script>

    ----------

    The link-text does appear, however the link appears as normal text so it aint clickable at all. I dunno how to fix it

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You are missing the closing quotes in this line

    <div id="dhtmlEl" style="visibility: hidden">

    You will also have to put this line in a function and run onload

    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';

    example

    function init(){
    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';
    }

    put onload="init()" in the opening body tag
    Last edited by Mr J; 07-30-2006 at 05:13 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, that quote thingy was a stupid error.

    I've got a question about that onload thingy... the way I did it, aint good ? It seems to work fine on my pc, the javascript executes normally.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    I am going to assume that you have your code in the body section in the order that you show in your first post.

    HTML

    SCRIPT

    Most scripts are usually put in the head section and without the onload your code would throw up an error
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,460
    Thanks
    0
    Thanked 632 Times in 622 Posts
    1. Check for window.external instead of IE to display the link as many browsers pretend to be IE but don't support window.external.

    2. Opera 9 uses ctrl-D and not ctrl-T to set a bookmark.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your replies.. I'll alter my code later today..

    Quote Originally Posted by felgall
    1. Check for window.external instead of IE to display the link as many browsers pretend to be IE but don't support window.external.
    Felgall, how can I check that ?


  •  

    Posting Permissions

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