基础版(立即跳转)
javascript
- <div><script>
- // 直接跳转
- window.location.href = "https://33rz.com/"; // 替换为你的目标地址
- </script></div>
复制代码
延时跳转版(3秒后跳转)
javascript
- <div><script>
- setTimeout(function(){
- window.location.href = "https://33rz.com/"; // 替换为你的目标地址
- }, 3000); // 单位:毫秒(3000ms=3秒)
- </script>
- </div>
复制代码
条件跳转版(带来源检测)
javascript
- <div><script>
- // 检测来源并跳转
- if (document.referrer.indexOf("特定域名") > -1) { // 修改判断条件
- window.location.href = "https://33rz.com/";
- }</div>
复制代码
// 示例:来自手机端跳转
- <div>if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
- window.location.href = "https://m.33rz.com/"; // 移动端地址
- }
- </script></div>
复制代码
点击跳转版(按钮触发)
html
- <div><button onclick="window.location.">点击跳转</button>
- 进阶功能版(带确认弹窗)
- javascript
- <script>
- if (confirm("确定要跳转到新页面吗?")) {
- window.location.replace("https://33rz.com/"); // 使用replace()不保留历史记录
- }
- </script></div>
复制代码
注意事项
代码位置建议:
立即跳转代码建议放在 <head> 标签内
交互类代码可以放在页面底部或事件回调中
跳转方法区别:
location.href (记录浏览器历史)
location.replace() (不记录历史)
location.assign() (与href效果类似)
安全提示:
部分浏览器会拦截非用户触发的跳转
频繁跳转可能被搜索引擎判定为作弊行为
需遵守各平台政策(如微信/App内可能有特殊限制)
|