当用户试图关闭当前选项卡或窗口时,我试图检测事件。我尝试了onbeforeunload和堆栈溢出答案。但是没有人为我工作。谁能帮我解决这个问题。我点击了this链接以获取答案,但对我不起作用。下面是我在chrome上测试过的代码。
Sub Tester()
Dim s As Shape, c, s2 As Shape
c = Application.Caller '<< name of your clicked shape
Debug.Print c
Set s = ActiveSheet.Shapes(c) '<< the clicked shape
With s.TextFrame2.TextRange.Characters
'here you need some way to transform the name of the clicked
' shape to get the name of the other shape to be shown/hidden/moved
Set s2 = ActiveSheet.Shapes(c & "_linked")
s2.Visible = (.Text = "Show")
.Text = IIf(.Text = "Show", "Hide", "Show") 'toggle text
End With
End Sub
谢谢。
答案 0 :(得分:1)
如果我还记得的话,那些“自定义”的配置消息不再起作用。 仅剩下浏览器的标准之一:
window.onbeforeunload = function(event) {
event.preventDefault();
return '';
};
当您单击“运行代码段”时,应在此页面上工作。