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

I have a post in category A that contain this redirection script:<script>window.location.replace("");<

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744835844a4596256.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信