...

View Full Version : showing div + add to favorites



cooldaddy
07-30-2006, 10:00 AM
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 :o

Mr J
07-30-2006, 05:10 PM
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

cooldaddy
07-30-2006, 06:07 PM
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.

Mr J
07-30-2006, 07:56 PM
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

felgall
07-30-2006, 09:32 PM
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.

cooldaddy
07-31-2006, 07:02 AM
Thanks for your replies.. I'll alter my code later today..


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 ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum