3

页面加载时如何自动单击“单信号”按钮?我正在尝试使用 javascript 和 jquery 代码,但它不起作用。

页面加载时,第一个代码在这里..

<div id="onesignal-bell-launcher" class="onesignal-bell-launcher onesignal-bell-launcher-md onesignal-bell-launcher-bottom-right onesignal-bell-launcher-theme-default onesignal-bell-launcher-active">
    <div class="onesignal-bell-launcher-button">
        <!--?xml version="1.0" encoding="utf-8"?-->
        <!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
        <svg version="1.1" class="onesignal-bell-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="99.7px" height="99.7px" viewBox="0 0 99.7 99.7" style="filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));; -webkit-filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));;" xml:space="preserve">
            <g>
                <circle class="background" cx="49.9" cy="49.9" r="49.9"></circle>
                <g id="Layer_2">
                    <g>
                        <path class="foreground" d="M50.1,66.2H27.7c0,0-2-0.2-2-2.1c0-1.9,1.7-2,1.7-2s6.7-3.2,6.7-5.5c0-2.3-1.1-3.9-1.1-13.3
                            s6-16.6,13.2-16.6c0,0,1-2.4,3.9-2.4c2.8,0,3.8,2.4,3.8,2.4c7.2,0,13.2,7.2,13.2,16.6s-1,11-1,13.3c0,2.3,6.7,5.5,6.7,5.5
                            s1.7,0.1,1.7,2c0,1.8-2.1,2.1-2.1,2.1H50.1z"></path>
                        <path class="foreground" d="M42.9,68.5h14.5c0,0-1,6.3-7.2,6.3S42.9,68.5,42.9,68.5z"></path>
                        <ellipse class="stroke" cx="49.9" cy="49.9" rx="37.4" ry="36.9"></ellipse>
                    </g>
                </g>
            </g>
        </svg>
        <div class="pulse-ring"></div>
    </div>
    <div class="onesignal-bell-launcher-badge"></div>
    <div class="onesignal-bell-launcher-message">
        <div class="onesignal-bell-launcher-message-body">Lütfen bildirimlere izin veriniz..</div>
    </div>
    <div class="onesignal-bell-launcher-dialog" style="filter: drop-shadow(0px 2px 2px rgba(34,36,38,.15));; -webkit-filter: drop-shadow(0px 2px 2px rgba(34,36,38,.15));;">
        <div class="onesignal-bell-launcher-dialog-body">
            <h1>Site bildirimlerini yönet</h1>
            <div class="divider"></div>
            <div class="push-notification">
                <div class="push-notification-icon push-notification-icon-default"></div>
                <div class="push-notification-text-container">
                    <div class="push-notification-text push-notification-text-short"></div>
                    <div class="push-notification-text"></div>
                    <div class="push-notification-text push-notification-text-medium"></div>
                    <div class="push-notification-text"></div>
                    <div class="push-notification-text push-notification-text-medium"></div>
                </div>
            </div>
            <div class="action-container">
                <button type="button" class="action" id="subscribe-button">TAKİP ET</button>
            </div>
            <div class="divider"></div>
            <div class="kickback">Powered by <a href="https://onesignal.com" class="kickback" target="_blank">OneSignal</a></div>
        </div>
    </div>
</div>

单击第一个按钮时,第二个按钮打开

<div class="action-container">
    <button type="button" class="action" id="subscribe-button">TAKİP ET</button>
</div>
4

5 回答 5

4

首先,你需要注册一个onclick事件,其中回调函数有必要的代码来添加元素,然后触发一个click事件

$( document ).ready(function() {
     $("#subscribe-button").on("click", function() {
          $(this).parent().append("<div class="action-container"><button type="button" class="action" id="subscribe-button2">TAKİP ET</button></div>")
     });
     $("#subscribe-button").trigger('click');
});

请记住,这里你应该有与第二个按钮不同的 id,没有 2 个 HTML 可以有相同的 id,如果你尝试获取元素,它只会从 DOM 中给你第一个

于 2016-05-13T07:08:53.987 回答
3

在这种情况下,您可以使用 jQuery。请在您的文档中添加新的 js 文件并将此代码放在上面:

$( document ).ready(function() {
     $("#ID OF YOUR BUTTON").trigger('click');
});

此代码在您的 html 文件加载完成并单击按钮时运行。

于 2016-05-13T07:02:24.497 回答
1

浏览器有一个内置的弹出窗口阻止程序,可以防止在加载页面时打开新窗口——用户必须首先单击链接或按钮。

由于 OneSignal 按钮会打开一个弹出窗口,因此用户必须自己单击它才能工作。

于 2016-05-13T18:09:52.310 回答
0

不幸的是,这种方法不起作用。我想onesignal可能已经采取了措施。我的网站是http://mucizeguvelik.com.tr,您可以查看 onesignal 按钮代码。

于 2016-05-13T07:27:02.390 回答
0

使用 jQuery,您可以在页面加载时自动单击按钮。尝试这个:

$(document).ready(function() {
     $("#subscribe-button").trigger('click');
});
于 2016-05-13T07:09:55.237 回答