【问题标题】:Add a popup legal notice to a website向网站添加弹出式法律声明
【发布时间】:2018-01-19 17:43:21
【问题描述】:

网站https://www.abeille-cyclotourisme.fr是手工制作的。不适用于 Wordpress 或任何 PHP 类型的数据库。

四天前,我在这个论坛上的“添加法律通知”主题上找到了非弹出式法律通知的解决方案。

较早的帖子:Add a legal notice to a website made of separate pages

我对脚本进行了转换,使法律声明将在单独的窗口中打开。

脚本,在根目录的“scripts”文件夹中,编写如下:

/* "Contactez nous"
    Crée un message comportant l'adresse mail de l'abeille
    et un texte dans le champ objet
*/

// Fonction htmlWindow_600 

  function htmlWindow_600(pagehtml) {
       htmlWindow = window.open(pagehtml, "minifenetre", "toolbar=yes,status=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=600,height=440")
       htmlWindow.focus()
  }

// Définition d'une variable contenant le début du code HTML

var liencontact="<a href='mailto:";

/* Ajout des diff&eacute;rents &eacute;l&eacute;ments de l'adresse mail
   dans la variable
*/
liencontact +="abeille-cyclotourisme";
liencontact +="@";
liencontact +="abeille-cyclotourisme.fr";
liencontact +="?subject=%5BAbeille%5D%20Demande%20d%27information'>";

// Affichage du lien vers "notice" et du lien mail 

document.write("<a href='https://www.abeille-cyclotourisme.fr/notice.html' target='lien'>Notice<\/a> - "+liencontact+"Contactez-nous @<\/a>");

我希望它在比标准页面窄的弹出窗口中打开,这样访问者会立即*看到他在弹出窗口中。更窄?我为站点的所有弹出窗口选择了 600 像素的宽度:所有 html 弹出窗口都使用脚本 htmlwindow_600。

为什么是弹出窗口?因为法律通知是死胡同。没有链接从它开始,而我希望它可以从任何页面访问 - 更准确地说是从任何页面的页脚。把它变成一个普通的页面,就像我到目前为止所做的那样,看起来很奇怪,因为一旦你在法律通知上,你就想离开它。在我看来,关闭弹出窗口是最干净的解决方案,但其他人可能会反对。

顺便说一句:为什么要在自行车网站上发布法律声明?因为我们将开始收集我们组织的活动的预注册姓名,并相信我们必须 (1) 尊重我们的访客并 (2) 为自行车俱乐部和董事提供保护。

我已经用上面的脚本语言编写了 htmlWindow_600 脚本的语言,作为参考和方便我的测试,但没有成功使用它,或者任何其他打开更窄窗口的脚本。

我试过了:

document.write("<a href='https://www.abeille-cyclotourisme.fr/notice.html' target='lien' onclick='javascript:htmlWindow_600('https://www.abeille-cyclotourisme.fr/notice.html');return false'>Notice - <\/a>"+liencontact+"Contactez-nous @<\/a>");

使用标准 html,点击“通知”会打开一个新窗口,但无法使用函数 htmlWindow_600 打开弹出窗口。我怎么能治好这个? TIA

【问题讨论】:

  • 弹出“法律通知”的目的是什么?
  • @mplungjan,您的意思是使用 AJAX 创建 XHR 请求以从文档本身获取 HTML 内容以将其呈现到对话框?
  • @Mr.Polywhirl 是的。一个 jQuery .load 类型的东西或在 iframe 中

标签: javascript html


【解决方案1】:

如果允许弹出窗口,它应该可以工作。更好的解决方案是使用不需要显示权限的对话框。

无论如何,试试这个 - 你的引号需要转义,但我设法通过传递 href 来避免这种情况:

注意:这两个链接在这里都不起作用,因为一个是 mailto 而另一个是弹出窗口,这两个链接都不允许在 stacksn-p 沙箱中运行

var liencontact="<a href='mailto:";

/* Ajout des diff&eacute;rents &eacute;l&eacute;ments de l'adresse mail
   dans la variable
*/
liencontact +="abeille-cyclotourisme";
liencontact +="@";
liencontact +="abeille-cyclotourisme.fr";
liencontact +="?subject=%5BAbeille%5D%20Demande%20d%27information'>";

document.write("<a href='https://www.abeille-cyclotourisme.fr/notice.html' target='lien'"+ 
" onclick='return htmlWindow_600(this.href)'>[Notice]</a> [" + liencontact + "Contactez-nous @</a>]");

function htmlWindow_600(pagehtml) {
  var htmlWindow = window.open(pagehtml, "minifenetre", "toolbar,status,menubar,location,scrollbars,resizable,width=600,height=440");
  if (htmlWindow) {
    htmlWindow.focus();
    return false;
  }
  return true; // this will open the rejected popup in a normal tab instead
}

【讨论】:

    【解决方案2】:

    正如 mplungjan 所说,弹出窗口不是最佳解决方案。我建议您使用模式,因为您将能够设计它以适合您的网站。 w3schools 网站上提供了一个非常简单的示例:https://www.w3schools.com/w3css/w3css_modal.asp

    如果您的法律声明很长,您可以使用滚动 div 甚至 iframe 到一个单独的页面,其中包含模态内的法律声明。

    【讨论】:

      【解决方案3】:

      谢谢大家。我试图在对原始帖子的编辑中回复 guest271314。

      garrettlynch 建议使用模态。我不知道什么是模态,什么是 CSS3。我将了解到,由于我认为值得尊重的原因,删除当前网站上所有存在的弹出窗口可能非常有用。

      对 garrettlynch 和 mplungjian 的附注:我同意要避免使用 javascript,并且要避免弹出窗口。至少,网站上所有当前的弹出窗口都是可降解的(如果 javascript 被“关闭”,它们仍然在 html 中执行)并且所有当前的 javascript 都可以降解为 html。

      mplungjian 然后为我可怜的 javascript 提出了一种治疗方法,并使其也可降解。 mplungjian治疗有效,完美。伟大的 !暂时可以这样做。然后我将学习我需要了解的有关 CSS3 和 modals 的知识。

      非常感谢大家。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-26
        • 1970-01-01
        • 2017-01-04
        相关资源
        最近更新 更多