网页常用代码 比较基础的东西


◆加入收藏夹
说 明 点击即可把你的网站添加到浏览器的收藏菜单下
代 码 <span style="CURSOR: hand" onClick="window.external.addFavorite('http://www.phpstudy.net','phpStudy')" title="phpStudy">收藏本站</span>

 

◆设为首页
说 明 点击即可把你的网站设置为浏览器的起始页
代 码 <span onclick="var strHref=window.location.href;this.style.behavior='url(#default#homepage)';
this.setHomePage('http://www.phpstudy.net');" style="CURSOR: hand">设为首页</span>

 

◆去掉超链接的下划线
说 明 有时候看着那超链接的下划线挺讨厌的,把下面这段代码放到网页源代码<head>与</head>之间,下划线就无影无踪啦!
注意,网页的<body>标签里不能再有link之类的属性,否则本效果会失效!
代 码 <style TYPE="text/css">
<!--
A:link{text-decoration:none}
A:visited{text-decoration:none}
A:hover {color: #ff00ff;text-decoration:underline}
-->
</style>

 

◆自动刷新网页
说 明 自动刷新网页
在HTML的与之间加入下面这段代码,则在5分钟之后正在浏览的页面将会自动变为target.html这一页。代码中300为刷新的延迟时间,以秒为单位。targer.html为你想转向的目标页,若为本页则为自动刷新本页。
代 码 <meta http-equiv="refresh" content="300; url=target.html">

 

◆刷新本页
说 明 点击即可刷新本页。
代 码 <a href="javascript:location.reload()" target="_self">刷新</a>

 

◆返回到上一页
说 明 点击即可返回到上一页面。
代 码 <a href="javascript:history.back(-1)">返回上一页</a>

 

◆跳出小窗口
说 明 在打开有下面这段代码的页面时将会跳出一个468x60大小的小窗口。“window.html”为跳出的小窗口里所要显示的网页。toolbar、status、menubar、scrollbars、设置小窗口的工具栏、状态栏、菜单栏及滚动条的有无,resizable设置是否可让浏览者改变小窗口大小,width、height设置小窗口的宽度以及高度。(不过这样的小窗口一般是不受欢迎的哦!)
代 码 <script language="JavaScript">
window.open("window.html","www_helpor_net","toolbar=no, status=no,menubar=no, scrollbars=no,resizable=no,width=468,height=60,left=200,top=50");
</script>

 

◆自动关闭窗口
说 明 在网页源代码中加入下面的代码,则该窗口将在20秒钟之后自动关闭!这与跳出式小窗口配合使用是再好不过啦!代码中“i=20”表示关闭的延迟时间为20秒,可任意修改。
代 码 <script language="javascript">
<!--
function clock(){i=i-1
document.title="本窗口将在"+i+"秒后自动关闭!";
if(i>0)setTimeout("clock();",1000);
else self.close();}
var i=20
clock();
//-->
</script>

 

◆给页面加保护
说 明 如果你不想让辛辛苦苦做出来的东西被人轻易地Copy&Paste走的话,不妨在HTML里加入下面这段代码。当在网页里按下鼠标右键时,出现的不是想要的快捷菜单而是一个警告窗口。“\n\n”表示换行。
代 码 <script language="JavaScript">
function helpor()
{
if (event.button==2)alert(' 仅供浏览!谢谢!\n\n若有问题请与我联系! ')
}
</script>

然后把<body> 改为 <body onmousedown="helpor_net()">

 

◆固定字号大小
说 明 你是否有过这样的经历:一个布置得很好的网页,当浏览时把浏览器的字号设置成大或小时,漂亮的网页马上面目全非了。因为字的大小变了,版式自然乱了。现在好了,只要把下面这段代码加入到网页源文件的<head>与</head>之间就行了(对用<font>标签定义的文字无效)。
代 码 <style type="text/css">
<!--
body {font-size:9pt}
td {font-size:9pt}
-->
</style>

 

◆状态栏里的动态欢迎语
说 明 浏览器的状态栏里出现一个字接一个字往左跑的欢迎语!
代 码 <script language="JavaScript">
<!--
function statusMessageObject(p,d) {
this.msg = MESSAGE
this.out = " "
this.pos = POSITION
this.delay = DELAY
this.i = 0
this.reset = clearMessage
}
function clearMessage() {
this.pos = POSITION
}
var POSITION = 100
var DELAY = 5
var MESSAGE = "欢迎光临! Welcome to WWW.phpstudy.net "
var scroll = new statusMessageObject()
function scroller() {
for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++) {
scroll.out += " "
}
if (scroll.pos >= 0)
scroll.out += scroll.msg
else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length)
window.status = scroll.out
scroll.out = " "
scroll.pos--
if (scroll.pos < -(scroll.msg.length)) {
scroll.reset()
}
setTimeout ('scroller()',scroll.delay)
}
function snapIn(jumpSpaces,position) {
var msg = scroll.msg
var out = ""
for (var i=0; i<position; i++)
{out += msg.charAt(i)}
for (i=1;i<jumpSpaces;i++)
{out += " "}
out += msg.charAt(position)
window.status = out
if (jumpSpaces <= 1) {
position++
if (msg.charAt(position) == ' ')
{position++ }
jumpSpaces = 100-position
} else if (jumpSpaces > 3)
{jumpSpaces *= .75}
else
{jumpSpaces--}
if (position != msg.length) {
var cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,scroll.delay);
} else {
window.status=""
jumpSpaces=0
position=0
cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,scroll.delay);
return false
}
return true
}
snapIn(100,0);
// -->
</script>

 

◆保护自己的页面不被别人放在框架中
说 明 有些人真是懒得可以,把别人做好的网页往自己网页的框架(Frame)里一放,别人的成果就变成了自己的,而且看不出该网页的真实地址!为了防止你的成果被这些人所剽窃,你就可以在你网页的HTML里加入下面这段代码,这样,你的网页便总是在整个窗口中打开了。
代 码 <Script LANGUAGE="JavaScript">
if(self!=top){top.location=self.location;}
</script>


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3