因此,当用户刷新页面时,我希望我的页面重定向到其他页面。我希望用户在刷新页面时从class SlideShow extends React.Component {
constructor(props, context) {
super(props);
this.state = {
slideIndex;
};
this.interval = null;
}
componentDidMount() {
this.interval = setInterval(this.transitionToNextSlide.bind(this), 200);
}
componentWillUnmount(){
if(this.interval){
clearInterval(this.interval);
}
}
transitionToNextSlide() {
this.setState({this.state.slideIndex: (this.state.slideIndex + 1) % this.props.slides.length})
render () {
let containerStyle = {
width:'100%'
};
return (
<div style={containerStyle}>
<Slide picture={this.props.pictures[this.state.currentSlide]}/>
</div>
);
}
};
重定向到index.html
。
CODE:
的index.html:
gettingstarted.html
gettingstarted.html
与<!DOCTYPE html>
<html lang="en">
<head>
//meta, seo stuff
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
//body stuff
//below is just a script that redirects to gettingstarted.html upon first visit
<script type="text/javascript">
function redirect(){
var thecookie = readCookie('doRedirect');
if(!thecookie){window.location = 'http://domain.tld/gettingstarted.html';
}}function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}window.onload = function(){redirect();createCookie('doRedirect','true','999');}
</script>
</body>
我尝试使用谷歌搜索,但我不断获得“元刷新标签”,在这种情况下,这是无用的。
答案 0 :(得分:0)
嗯..你可以这样做:
if ( document.referrer == null || document.referrer.indexOf(window.location.hostname) < 0 ) {
sessionStorage.setItem("is_reloaded", true);
}
// This one will set the sessionStorage.setItem on first visit
if (sessionStorage.getItem("is_reloaded")) {
location.href = 'http://domain.tld/gettingstarted.html';
}
//Next time then if someone reload the page so it will reload the user to that another link
如果第一个不起作用,请尝试将其作为:
window.onbeforeunload = function(e) {
location.href = 'http://domain.tld/gettingstarted.html';
};
答案 1 :(得分:0)
这将执行您要求的操作,只需自定义网址。
<script>
if (sessionStorage.getItem('beenhere') ==='1') {
window.location="http://www.example.com";
}
sessionStorage.setItem('beenhere', '1');
</script>
请参阅: