简体   繁体   中英

Create Redirect Page For All External Link Blogspot

I want make Some External link Redirect to my Specific Page when leaving my site. I was try safelink before, but it need to create other New Blog to redirect all External Link.

Some thing that I mean, example:
https://updated2apks.blogspot.co.id/2017/09/whats-different-100-mod-apk.html

If click External link, it will redirect to Specific Page

https://updated2apks.blogspot.com/p/your-apk-is-ready-for-download.html?id=com.qs.whatsdifferent.html

And Finally leave the Blog and go to Target link (External) Because this is Blogspot platform, I tried search in Google, but it's lack of tutorial. I hope some one here can help me.

If I understand your question correct, this is a possible solution, that would redirect the page first to your page and than to the external page.
(This would have to be done in the Theme)

Here is an example:
(If the external url uses Parameters or so the code will have to be adapted)

<script>
    // Here we check if the current page is the redirect catch page
    if("http://URL_THAT_SHOULD_CATCH_REDIRECTS.html" === "<data:blog.url/>")
    {
        // Here we assume there is only one parameter in the URL, with our external Link
        var parameter = location.search.split(/\?|=/g).slice(1);
        // Here we check if the size of the array is valid, checking for the parameter name would be also good. Maybe even checking if the passed URL is valid
        if(parameter.length===2){
            // Here we redirekt to the URL that is the Value of the passed parameter
            location.href=parameter[1];
        }

     }
</script>   

Example result:

external URL is "www.google.com"
url to redirect to is "great.blogger.com/p/redirect_page.html"
the a-Tag for the blog is <a href="http://"great.blogger.com/p/redirect_page.html?redirect=www.google.com">LINK</a>

Hint: If the external url has parameters the url has to be encoded. If the redirect Url has parameters, you have to find the correct parameter, that contains the URL.

Info: If the href is set directly to the external page you would need additional Code for creating the correct redirect link, using EventListener on the a -tag preventing the default behavior and than redirecting in that code. (Here some Infos on MDN about preventDefault function )

Could look like this:

document.getElementById("aLinkId").addEventListener("click", function(e){
    e.preventDefault();
    // Here we redirect to the wanted page, with the extra parameter, with the original external URL
    location.href = "REDIRECT_URL?redirect="+ document.getElementById("aLinkId").href; 
});

All code tested with Chrome 60+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM