我对这些代码还很陌生,但是我会尽力解释,以使您更好地理解。
我想要的是,我想在Blogger中创建一个页面,该页面将在5-10秒后重定向。就像php一样,我们可以通过该页面重定向任何外部url(下载链接)。我找到了一些代码,但未正确重定向,在下面显示...
<h3>Page Will Redirect After <span id="countdown">10</span> seconds</h3>
<!-- JavaScript part -->
<script type="text/javascript">
// Total seconds to wait
var seconds = 20;
function countdown() {
seconds = seconds - 1;
if (seconds < 0) {
// Chnage your redirection link here
window.location = "https://www.google.com";
} else {
// Update remaining seconds
document.getElementById("countdown").innerHTML = seconds;
// Count down using javascript
window.setTimeout("countdown()", 1000);
}
}
// Run countdown function
countdown();
</script>
With this code i made a page (example: abc.blogspot.com/p/go.html) and i add link in post "<a href="http://abc.blogspot.com/p/go.html?redirect=www.facebook.com">LINK</a>"
but it's not redirect to facebook because in code mention : "window.location = "https://www.google.com";"
我如何在Blogger中使用计时器创建重定向页面,并用html代码重新映射帖子中的所有外部链接?
答案 0 :(得分:0)
您需要从URL获取“查询参数”,并将google链接更改为该链接。
var seconds = 20;
var urlParams = new URLSearchParams(window.location.search);
var redirectLink = urlParams.get('redirect');
// CAUTION: assumes the redirectLink passed in URL is a valid URL.
// that is, it starts with a protocol - http://, https://
function countdown() {
seconds = seconds - 1;
if (seconds < 0) {
// Chnage your redirection link here
window.location = redirectLink;
} else {
// Update remaining seconds
document.getElementById("countdown").innerHTML = seconds;
// Count down using javascript
window.setTimeout("countdown()", 1000);
}
}
// Run countdown function
countdown();
<h3>Page Will Redirect After <span id="countdown">10</span> seconds</h3>
建议语:除非您有充分的理由这样做,否则请不要。
答案 1 :(得分:0)
感谢@ Sudhanshu Vishnoi,它可以正常工作,但是整个页面的URL和下载链接显示如下示例:
<a href="http://abc.blogspot.com/p/go.html?redirect=http://www.mediafire.com/file/code.rar">LINK</a>
有什么办法隐藏下载链接,因为您知道人们的状况,他们不想5或10秒钟,他们会复制下载链接,所以我想隐藏整个url或至少一个下载链接,这可能吗?如果是,那怎么办?