通过 HTML 文档 Head 中的 Script Tag 加载 JS 时处理重定向

发布于 2024-10-16 12:23:24 字数 271 浏览 4 评论 0原文

有两种情况:

1)我使用 script 标签从 facebook 站点加载 JS 文件。如果该站点被网络访问管理器(websense)阻止,我们将收到 302 响应并自动重定向到某个页面。这种情况该如何处理呢?

2) 如果第 1 点通过,那么它会在内部创建一个 IFrame 并尝试访问另一个 facebook 站点,如果它被阻止,那么同样的事情会发生,但这次一些文本将与用户可见的其他页面内容一起出现在页面上。这要怎么处理呢?

请帮我一下。

问候, 光伏发电

There are 2 cases:

1) I am loading JS file from facebook site by using script tag.If this site is blocked by network access manager (websense) we are getting 302 response and autmatically redirected to some page. How to handle this condition ?

2) if point #1 passes then it internally creates an IFrame and try to access another facebook site now if this is blocked then same thing will happen but this time some text will appear on page along with other Page content visible to user. How to handle this ?

Please help me out here.

Regards,
PV

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

触ぅ动初心 2024-10-23 12:23:24

处理第一种情况的最简单方法是检查 Facebook 的 javascript 加载的变量或命名空间。

// lets assume the facebook js file contains a "fb" namespace
if(fb || window.fb){
  // do some action since we have facebook loaded
  var fbFrame = document.getElementsByTagName('iframe')[0];
  fbFrame.onerror = function(){
    // facebook failed to load :( do redirect
    window.location.href = "someOtherPage.html";
  };
}else{
  // facebook failed to load :( do redirect
  window.location.href = "someOtherPage.html";
}

对于第二部分,您可以向 iframe 添加 onerror 事件侦听器。当加载 iframe 时发生错误时,将调用 onerror 处理程序。

这是一个涵盖它的好问题:如何处理以下错误加载 iframe?

The easiest way to handle the first case is to check for a variable or namespace loaded by the javascript from Facebook.

// lets assume the facebook js file contains a "fb" namespace
if(fb || window.fb){
  // do some action since we have facebook loaded
  var fbFrame = document.getElementsByTagName('iframe')[0];
  fbFrame.onerror = function(){
    // facebook failed to load :( do redirect
    window.location.href = "someOtherPage.html";
  };
}else{
  // facebook failed to load :( do redirect
  window.location.href = "someOtherPage.html";
}

For the second part, you can add an onerror event listener to the iframe. When an error occurs loading the iframe, the onerror handler will be invoked.

Here's a good question that covers it: How can I handle errors in loading an iframe?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文