简体   繁体   English

为什么在Firefox,Safari和Internet Explorer中不支持点击处理程序事件SVG元素?

[英]Why doesn't support click handler event SVG element in Firefox and Safari and Internet Explorer?

The web application 网络应用

It is a web-based finding map game site built with Angular 4. It has various selection game mode and runs based on the selection mode also many regions that can choose/select or only one region then populate the country name to find each cycle. 它是一个基于Angular 4的基于Web的查找地图游戏网站。它具有多种选择游戏模式,并基于选择模式运行,许多区域可以选择/选择,或者仅一个区域然后填充国家/地区名称以查找每个周期。

What should be the correct behavior 什么是正确的行为

*All data populating from SVG document *所有数据均来自SVG文档

  1. After page load - Options to choose ['New Game', 'Achievement', 'HighScore'] 页面加载后-用于选择['New Game','Achievement','HighScore']的选项
  2. Choose a game mode ['learning', 'classic', 'time'] 选择游戏模式[“学习”,“经典”,“时间”]
  3. Select regions (one or more) then press play to play the game 选择地区(一个或多个),然后按Play玩游戏
  4. Display the SVG map and name to find a country randomly from SVG 显示SVG地图和名称以从SVG中随机查找国家
  5. Click on a country then if a user clicked correct country notification 'correct' if not notification would be 'incorrect' (there are the logic that can count the correct/incorrect point) 单击一个国家/地区,然后,如果用户单击正确的国家/地区通知,则单击“正确”;如果未单击通知,则单击“正确”(存在可以计算正确/错误点的逻辑)
  6. Move next Country to find (then repeat step 5) 移动下一个国家来查找(然后重复步骤5)
  7. End game 结束游戏
  8. It should work all in the major Browsers (Chrome, Firefox, Safari, Edge, Internet Explorer) 它应该在所有主要浏览器(Chrome,Firefox,Safari,Edge,Internet Explorer)中都能正常工作

Game Mode 游戏模式

  • LearningMode = always repeat game LearningMode =总是重复游戏

  • ClassicMode = run only one time and end ClassicMode =仅运行一次并结束

  • TimeMode = has a time limit to finish otherwise game over TimeMode =有时间限制,否则游戏结束

Here is a partial code it handles the click event 这是处理click事件的部分代码

public handleClickEvent(event: any): void {
  if (this.gameStarted && event.path && event.path.length > 0) {
    const country = event.path[0].id;
    if (
      country !== null &&
      country !== 'europeanMap' &&
      country !== 'image97'
    ) {
      this.runGameLogic(country);
    }
  }
}

Game run logic 游戏运行逻辑

// The user clicked on the map, so run game logic on that

  private runGameLogic(selectedCountryName: string): void {
    const index = this.selectedCountries.findIndex(country => {
      return country.name === this.countryToFind.name;
    });
    this.selectedCountries[index].selected = true;
    // Only run logic if the game has started, there is a valid countryName object, and that object is not equal to an empty string
    if (selectedCountryName && selectedCountryName !== '') {
      if (selectedCountryName === this.countryToFind.name) {
        this.correctAnswerLogic(index);
        this.selectedCountries[index].correct = true;
      } else {
        this.incorrectAnswerLogic(index, selectedCountryName);
      }
    }
  }

I need to figure out how I can make cross-browser capabilities app or what could be possible solutions that the browser does support mine app. 我需要弄清楚如何制作跨浏览器功能的应用程序,或者浏览器确实支持我的应用程序的可能解决方案。

Thank you for help :) 谢谢你的帮助:)

I got the solution for the Firefox browser. 我得到了Firefox浏览器的解决方案。 The reason was Firefox doesn't have event.path property and it doesn't triggering the click event though I found this event.composedPath() it works with all major browser except Edge/IE more detail in Mozilla Documentation . 原因是Firefox没有event.path属性,并且没有触发click事件,尽管我发现此event.composedPath()可以与所有主要浏览器一起使用,但Mozilla文档中的 Edge / IE除外。 Here is an actual code that works fine on Firefox. 这是在Firefox上可以正常运行的实际代码。

public handleClickEvent(event: any): void {
  const path = event.path || event.composedPath();
  if (this.gameStarted && path && path.length > 0) {
    const country = path[0].id;;
    if (
      // some conditions
    ) {
      // do something
    }
  }
}

I still need to solve in the Edge/IE browser. 我仍然需要在Edge / IE浏览器中解决。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM