【问题标题】:sockjs shows popup to save iframe.json file in IEsockjs 显示弹出窗口以在 IE 中保存 iframe.json 文件
【发布时间】:2021-04-22 18:09:40
【问题描述】:

我正在使用 spring-boot WebSocket 和 SockJsClient 进行通知。 用户在 IE 中登录系统后,将显示以下弹出窗口,

以下是 UI (ReactJS) 代码:

<SockJsClient url={"URL"} topics={["topicname"]} onMessage={this.showNotificationCount} ref={(client) => { this.clientRef = client }} options={["xhr-polling"]} />)

后端代码(Java spring-boot):

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer
{
  @Override
  public void configureMessageBroker(MessageBrokerRegistry config)
  {
     config.enableSimpleBroker("/topic", "/user");
     config.setApplicationDestinationPrefixes("/app");
  }

  @Override
  public void registerStompEndpoints(StompEndpointRegistry registry)
  {
      registry.addEndpoint("/notification-websocket").setAllowedOrigins("*").withSockJS().setWebSocketEnabled(false);
  }
}

弹出文件内容:

我们可以禁用这个弹出窗口吗?

【问题讨论】:

  • IE 11的控制台有错误吗?您是否在其他浏览器的网络选项卡中查看过是否有这样的文件要下载?我在 github 中找到了a similar thread,您可以尝试 cmets 中的解决方案。该问题可能与 CORS 有关,您可以查看this source code 了解它是如何发生的。
  • 感谢@YuZhou的回复,IE没有控制台错误,其他浏览器也没有下载此类文件。

标签: internet-explorer websocket spring-websocket sockjs


【解决方案1】:

来自官方文档的this part,在副标题4.3.3的第5段中。 IE 8 和 9,它说:

Spring SockJS 支持还需要知道 SockJS 客户端的位置,因为它是从 iframe 加载的。默认情况下,iframe 设置为从 CDN 位置下载 SockJS 客户端。

我想这就是为什么你会得到 iframe 的下载信息。

最好将此选项配置为使用与应用程序同源的 URL。

所以你可以尝试像文档中的示例一样进行配置:

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/portfolio").withSockJS()
            .setClientLibraryUrl("http://localhost:8080/myapp/js/sockjs-client.js");
}

【讨论】:

  • 试过了,但没有成功!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-14
相关资源
最近更新 更多