How to Check if URL exists using javascript

后端 未结 1 1264
生来不讨喜
生来不讨喜 2020-12-11 14:01

I need to check if a URL exists and redirect a user if it\'s not, we support various browsers (IE, Chrome, Firefox etc...) so the solution needs to be able to support all of

1条回答
  •  孤城傲影
    2020-12-11 14:32

    In the header of your page, place this javascript code:

            
    


    This allows you to check whether or not a page exists on your server and redirect to it if it does. If the page does not exist, the javascript code does nothing and allows the current page to load.

    Edit: Fixed bugs and rewrote some of the code for clarity, appearance, and practicality.

    0 讨论(0)
提交回复
热议问题