즐겨찾기 및 시작페이지 추가 IE FF모두 가능
Scripter/JAVASCRIPT / 2008. 3. 6. 12:51
네이버에 등록했던글을 티스토리로 옮기다.
크로스브라이징이 되야하는 웹사이트개발건이 있어 즐겨찾기 및 시작페이지에 추가하는 기능을 꼬불쳐두다.
데꾸벅이 사용하는 소스
(IE7,IE8 Beta, FF2, FF3 Beta 이상없이 작동), Opera 작동 안함..
/**
* 즐겨찾기 등록하기
*/
function CreateBookmarkLink(urlStr) {
title = "넥스트리소프트";
url = urlStr;
//FF
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
}
//IE
else if( window.external ) {
window.external.AddFavorite( url, title);
}
//Opera
else if(window.opera && window.print) {
return true;
}
}
/**
* 시작페이지 설정
*/
function startPage(Obj,urlStr){
if (document.all && window.external){
Obj.style.behavior='url(#default#homepage)';
Obj.setHomePage(urlStr);
} else {
}
}
<a onClick="startPage(this,'http://www.nextree.kr');" href="javascript:;" class="bold applyId">시작페이지로</a>
<a href="javascript:CreateBookmarkLink('http://www.nextree.kr');">즐겨찾기 등록</a>
* 즐겨찾기 등록하기
*/
function CreateBookmarkLink(urlStr) {
title = "넥스트리소프트";
url = urlStr;
//FF
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
}
//IE
else if( window.external ) {
window.external.AddFavorite( url, title);
}
//Opera
else if(window.opera && window.print) {
return true;
}
}
/**
* 시작페이지 설정
*/
function startPage(Obj,urlStr){
if (document.all && window.external){
Obj.style.behavior='url(#default#homepage)';
Obj.setHomePage(urlStr);
} else {
}
}
<a onClick="startPage(this,'http://www.nextree.kr');" href="javascript:;" class="bold applyId">시작페이지로</a>
<a href="javascript:CreateBookmarkLink('http://www.nextree.kr');">즐겨찾기 등록</a>
여기저기서 긁어모아 꼬불쳐둔 소스
<script type="text/javascript" language="JavaScript">
function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{
window.sidebar.addPanel("홈페이지 타이틀 혹은 소개글","홈페이지 주소");
}else {
window.external.AddFavorite("홈페이지 주소","홈페이지 타이틀 혹은 소개글");
}
}
</script>:void(favoris());" mce_href="javascript:void(favoris());">즐겨찾기에 추가</a>
function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{
window.sidebar.addPanel("홈페이지 타이틀 혹은 소개글","홈페이지 주소");
}else {
window.external.AddFavorite("홈페이지 주소","홈페이지 타이틀 혹은 소개글");
}
}
</script>
<script>
function addBookmarkForBrowser() {
if (document.all)
{
window.external.AddFavorite(document.location.href , document.title);
} else {
var ea = document.createEvent("MouseEvents");
ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
var eb = document.getElementsByTagName("head")[0];
eb.ownerDocument getter = new Function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
eb.dispatchEvent(ea);
}
}
</script>
<a href="javascript:addBookmarkForBrowser();">Add to Favorites</a>
function addBookmarkForBrowser() {
if (document.all)
{
window.external.AddFavorite(document.location.href , document.title);
} else {
var ea = document.createEvent("MouseEvents");
ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
var eb = document.getElementsByTagName("head")[0];
eb.ownerDocument getter = new Function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
eb.dispatchEvent(ea);
}
}
</script>
<a href="javascript
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BOOKMARK & HOMEPAGE</title>
<script language="JavaScript1.2" type="text/javascript">
function CreateBookmarkLink() {
title = "Men's Health Information, Including Fitness, Nutrition, Weight Loss, Working Out & Sex";
url = "http://www.mens-health.com/";
if (window.sidebar) {
// Mozilla Firefox Bookmark
alert("FIREFOX!");
window.sidebar.addPanel(title, url,"");
} else if( window.external ) {
// IE Favorite
alert("YES IE");
window.external.AddFavorite( url, title);
}
else if(window.opera && window.print) {
// Opera Hotlist
return true; }
}
</script>
</head>
<body bgcolor="#ffffff">
<a href="javascript:CreateBookmarkLink();">Add to Favorites</a>
<br><br>
<a href="#" onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage('http://www.google.com');">Set homepage </a>
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BOOKMARK & HOMEPAGE</title>
<script language="JavaScript1.2" type="text/javascript">
function CreateBookmarkLink() {
title = "Men's Health Information, Including Fitness, Nutrition, Weight Loss, Working Out & Sex";
url = "http://www.mens-health.com/";
if (window.sidebar) {
// Mozilla Firefox Bookmark
alert("FIREFOX!");
window.sidebar.addPanel(title, url,"");
} else if( window.external ) {
// IE Favorite
alert("YES IE");
window.external.AddFavorite( url, title);
}
else if(window.opera && window.print) {
// Opera Hotlist
return true; }
}
</script>
</head>
<body bgcolor="#ffffff">
<a href="javascript
<br><br>
<a href="#" onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage('http://www.google.com');">Set homepage </a>
</body>
try{
window.external.AddFavorite(window.location.href, document.title);
}catch(e){
this.href = window.location.href;
this.title = document.title;
this.rel = "sidebar"
}
window.external.AddFavorite(window.location.href, document.title);
}catch(e){
this.href = window.location.href;
this.title = document.title;
this.rel = "sidebar"
}
'Scripter > JAVASCRIPT' 카테고리의 다른 글
Browser detect (0) | 2008.03.06 |
---|---|
IE7, FF3 에서 전체화면 팝업창 띄우기 (0) | 2008.03.06 |
자바스크립트로 구현한 3D 포토갤러리 (0) | 2008.03.06 |
JsonSQL: JSON parser, SQL style (0) | 2008.03.06 |
Native CSS selectors with querySelector (0) | 2008.03.06 |