最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - A post has a js redirection script. How to not redirect its category?

programmeradmin3浏览0评论

I have a post in category A that contain this redirection script:

<script>window.location.replace("");</script>

However, when I click on A, it also redirects. How to prevent this?

I have a post in category A that contain this redirection script:

<script>window.location.replace("http://www.w3schools");</script>

However, when I click on A, it also redirects. How to prevent this?

Share Improve this question asked Jan 14, 2020 at 18:50 OokerOoker 3324 silver badges23 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

If that redirection script is written in the content section of the post, it is probably being called in with the rest of the content on the category page.

You could add a URL check to your javascript that would look like this:

if(document.URL.indexOf("foo_page.html") >= 0){ 
    window.location.replace("http://www.w3schools");
}

And add in your permalink to the if statement

A post has a js redirection script.

Full Stop. If you're redirecting anything in JS, start from there as the first failure point. There's really no reason anything should be redirecting from JS on the front end. There are plenty of redirection plugins out there to handle any redirection rules you might need. Delete the script, redirect the page properly, and move on.

There are of course ways to "fix" what you're trying to do, i.e. strip any scripts out of the post content before outputting it on the category pages, which you should be doing anyway. But you're still better off not having a redirect performed from the front end in JS.

发布评论

评论列表(0)

  1. 暂无评论