如何让 link 转到页面并在其中切换弹出窗口?

How can I make link go to a page and toggle popup in it?

我需要 link 打开某个页面,然后立即切换其中的隐藏弹出窗口。弹出窗口通常通过单击该页面上的指定按钮显示。这可能吗?我需要这个作为 html 电子邮件模板,所以不确定 javascript 是否有效

我会在电子邮件中的 link 中附加一个 URL 参数...类似 ?popup=true

然后,在您 link 在 JavaScript 中编辑到的页面上,您可以检查 URL 参数,然后显示弹出窗口。

var urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('popup') === 'true') {
    // show popup code here... $('.popup').show() if using jQuery...
}

URL虽然 https://caniuse.com/#feat=urlsearchparams

SearchParams 在 IE 中不起作用

所以如果你需要支持IE你可以使用这个函数代替

function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\[').replace(/[\]]/, '\]');
    var regex = new RegExp('[\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};