# 使用Javascript指定弹窗的显示

在营销活动设置中，您可以根据用户在网站上的行为，在适当的时间显示内容。其中，弹窗和固定栏可以通过Javascript代码更自由地控制显示时间。详细信息请见下文。

> **INFO** \*\*Note：\*\*Javascript代码控制仅适用于弹窗和固定栏，不适用于网站编辑。此外，可在一个会话内多次触发。

## 配置方法

如下图所示，创建创意后，在"显示/停止条件"的设置中选择使用Javascript代码显示。

可以使用如下所示的Javascript代码来控制弹窗或固定栏的触发。 `ptengine && ptengine.showEngagement('xxxxxxxx');`

**Note：** ・ID因创意、设备和版本而异，请始终获取正确的ID。 ・如果进行A/B测试，需要实现每个版本的所有代码。 ・如果在PC和移动设备上配置营销活动，需要实现每个设备的所有代码。

复制Javascript代码，将其实现到要显示的页面上，并在要显示的时间触发它。

完成营销活动设置并保存。

## 实现示例

添加到HTML时 `<button id="loginBtn" onclick="ptengine && ptengine.showEngagement('xxxxxxxx')">login</button>`

添加到原生Javascript时 `document.getElementById("loginBtn").addEventListener("click", function(){ ptengine && ptengine.showEngagement('xxxxxxxx') });`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://helps.ptengine.com/cn/faq/experience-edit/javascript-popup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
