[英]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文档
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.