是否可以在javascript中添加浏览器代码 [英] Is it possible to add a browser code in javascript

查看:79
本文介绍了是否可以在javascript中添加浏览器代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在javascript中创建具有浏览器特定网页。



例如:



我在我的网页中使用这样的代码在我的编码部分



chrome.tab.onRemoved.addListener()



如果可能请建议我。

解决方案



如果您想知道网页加载标签何时关闭,则 window.onunload 应该会帮助你。



如果你想知道

更新:

您说您想知道什么时候用户关闭浏览器或选项卡。这是不可能的。



但是为了您的目的(获得反馈),我认为您需要的是区分用户是否导航到您的页面中的链接,或用户是否键入另一个URL(或通过点击收藏夹)。



我认为根据您的要求,无论用户关闭浏览器,是相同的 - 用户正在离开您的网站,当时您说您想要收集反馈。



这可以在javascript中完成。


对于页面中的所有点击,
可能会导致页面刷新
(超链接,按钮...) ,设置一个标志。

window.onunload 中,检查是否设置了
此标志。

- 如果它被设置,然后
用户已经在您的
页面中点击了一个链接,什么都不做。

- 如果标志不是
设置,则用户离开,
收集反馈的时间。


让我知道这是否有效。



PS:请注意,在window.unload期间弹出窗口/任何分心可能是非常讨厌。
我理解这可能是给你的要求。但如果可能,请尝试其他机制来收集(自愿)用户反馈。


I would like to create a webpage with browser specific in javascript.

For example:

can I use code like this in my coding part

chrome.tab.onRemoved.addListener() in my webpage.

If it is possible please suggest me.

解决方案

What exactly are you tring to acheive?

If you want to know when the tab in which your webpage is loaded is closed, then window.onunload should help you.

If you want to know when another webpage is closed, you cannot do this.

UPDATE:
You said that you want to know when the user closes the browser or tab. This is not possible.

But for your purpose (getting feedback), I think all you need is to differentiate whether the user is navigating to a link in your page, or whether the user is typing another URL(or by clicking a favorite).

I think for your requirement, whether the user closes the browser, or whether he types another URL, is the same - the user is navigating away from your site, and at that time you say you want to collect feedback.

This can be done in javascript.

For all the clicks in your page that might lead to a page refresh (hyperlinks, buttons,...), set a flag.
In window.onunload, check whether this flag is set.
- If it is set, then the user has clicked a link in your page, do nothing.
- If the flag is not set then the user is navigating away, time to collect feedback.

Let me know if this would work.

PS: Note that popups/any distractions during window.unload can be very annoying. I understand that this probably is the requirements given to you. But if possible, try other mechanisms to collect (voluntary) feedback from the user.

这篇关于是否可以在javascript中添加浏览器代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆