Grails - 将链接作为参数传递

发布于 2024-12-07 08:02:10 字数 289 浏览 6 评论 0原文

我在我的网络应用程序中实现了电子邮件共享服务。人们可以单击电子邮件按钮并访问一个表单,通过该表单可以向他们想要的人发送电子邮件。

我想设置默认的主题正文

在电子邮件的默认正文中,我想传递人们想要共享的页面的链接。当然可以这样做,但我做不到。 到目前为止,尝试在文本编辑器的 value 参数中传递链接一直是一个死胡同。我想不出还有什么其他方法可以做到这一点。

任何建议都非常感激。

I have implemented an email sharing service in my web application. People can click on the email button and access a form with which they can send emails to whom they want.

I would like to set a default subject and body.

In the default body text of the email, I would like to pass the link of the page people want to share. Surely it is possible to do so but I do not manage to.
So far it has been a dead end to try to pass the link in the value argument of my text editor. I cannot think if any other way to do it.

Any suggestion greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把回忆走一遍 2024-12-14 08:02:10

与将数据传递到要填充的任何其他字段的方式相同。

例如,您的控制器返回一个模型 emailShare ,其中包含 subjectbodyurl

在您的 gsp 中,可以说您的电子邮件正文有一个文本区域,

<g:textField name="emailSubject" value="${emailShare.subject}" />
<g:textArea name="emailBody" value="${emailShare.url}" rows="5" cols="40"/>

这会将 url 设置为文本区域中的默认文本,也可以进一步编辑该文本以添加更多文本。

The same way you pass data to any other fields that you want to populate.

For example your controller returns a model emailShare that contains subject, body and url etc

In your gsp, lets say you have a textarea for the body of your email,

<g:textField name="emailSubject" value="${emailShare.subject}" />
<g:textArea name="emailBody" value="${emailShare.url}" rows="5" cols="40"/>

This will set the url as the default text in the textarea, which can also be further edited to add more text.

扛刀软妹 2024-12-14 08:02:10

您可以使用 JavaScript 和 document.URL 获取当前页面的位置,然后您只需在表单上设置一个隐藏字段并通过电子邮件请求提交即可。例如:

<html>
<head>
<script type="text/javascript">
     function setLocation(urlField) {
       urlField.value = document.URL
     }
   </script>
</head>
<body>

  <form id="exampleForm" name="exampleForm" action="#">
    <input type="text" id="url"  name="url"/>
    <input name="submit" value="submit" type="button" onclick="setLocation(this.form.url);" />
  </form>
  </body>
</html>

You can get the location of the current page using JavaScript with document.URL Then you can just set a hidden field on your form and submit it with your email request. For example:

<html>
<head>
<script type="text/javascript">
     function setLocation(urlField) {
       urlField.value = document.URL
     }
   </script>
</head>
<body>

  <form id="exampleForm" name="exampleForm" action="#">
    <input type="text" id="url"  name="url"/>
    <input name="submit" value="submit" type="button" onclick="setLocation(this.form.url);" />
  </form>
  </body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文