如果错误等于_做这个Javascript / jQuery

时间:2014-04-02 06:46:41

标签: javascript jquery html redirect

今天我正在尝试用javascript / jQuery来做这件事;发生错误时,此错误例如

Refused to display 'http://example.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN, SAMEORIGIN'.

该脚本将运行一个函数将它们重定向到他们去往的网站。

2 个答案:

答案 0 :(得分:1)

你可以这样做:

try{
  //some bug
}
catch(ex){
  if(ex=="Some Error Message"){
    //do something here
   }
}

答案 1 :(得分:1)

使用try / catch

try {
    //some code to do
} catch(exc){
    if(exc == "Refused to display 'http://example.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN, SAMEORIGIN'."){
        //your redirect code here
    }
}

如果错误是其他错误,只需用错误替换Refused to display 'http://example.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN, SAMEORIGIN'.