css怎么跳转页面?页面跳转的5种方法 !

猿友 2021-07-01 14:24:35 浏览数 (10706)
反馈

我们在正常的网页开发中往往一个页面是不能满足我们的需求的,所以我们就需要使用到多页面来进行实现我们的功能,那么今天我们就来说说有关于:“css怎么跳转页面?”这个问题吧!下面是小编查询和整理的相关内容资料,希望对大家的学习和理解有所帮助!


1、html实现

代码如下:

<head>
<!-- 以下方式只是刷新不跳转到其他页面 -->
<meta http-equiv="refresh" content="10">
<!-- 以下方式定时转到其他页面 -->
<meta http-equiv="refresh" content="5;url=hello.html"> 
</head>

对于这个方法我们实现会相对的比较简单,但是不足的点就是 Struts Tiles 中无法使用。


2、JavaScript实现

代码如下:

<script language="javascript" type="text/javascript"> 
// 以下方式直接跳转
window.location.href='hello.html';
// 以下方式定时跳转
setTimeout("javascript:location.href='hello.html'", 5000); 
</script>

通过使用JavaScript这个方法,它是属于比较灵活可以让我们结合更多其他功能的,但是有不足的是会受到不同浏览器的影响。


3、在firefox中结合倒数JavaScript实现

代码如下:

<script language="javascript" type="text/javascript"> 
var second = document.getElementById('totalSecond').textContent; 
setInterval("redirect()", 1000); 
function redirect() 
{ 
document.getElementById('totalSecond').textContent = --second; 
if (second < 0) location.href = 'hello.html'; 
} 
</script>

4、解决Firefox不支持innerText的问题

代码如下所示:

<span id="totalSecond">5</span>
<script language="javascript" type="text/javascript"> 
if(navigator.appName.indexOf("Explorer") > -1){ 
document.getElementById('totalSecond').innerText = "my text innerText"; 
} else{ 
document.getElementById('totalSecond').textContent = "my text textContent"; 
} 
</script>

5、整合

<span id="totalSecond">5</span>
 
<script language="javascript" type="text/javascript"> 
var second = document.getElementById('totalSecond').textContent; 
 
if (navigator.appName.indexOf("Explorer") > -1)  { 
    second = document.getElementById('totalSecond').innerText; 
} else { 
    second = document.getElementById('totalSecond').textContent; 
} 
 
setInterval("redirect()", 1000); 
function redirect() { 
if (second < 0) { 
    location.href = 'hello.html'; 
} else { 
    if (navigator.appName.indexOf("Explorer") > -1) { 
        document.getElementById('totalSecond').innerText = second--; 
    } else { 
        document.getElementById('totalSecond').textContent = second--; 
    } 
} 
} 
</script>

小结:以上的例子都是主要来实现在五秒之后自动跳转到同一目录下的 hello.html文件中。


总结:

关于“css怎么跳转页面?”这个问题,今天我们也结束了介绍,如果你有其他的想法也可以分享你的看法和大家一同分享,更多有关于前端方面的知识我们都可以在W3Cschool中进行学习和了解。


0 人点赞