开发者

Grails - Pass a link as a parameter

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.


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜