HTML
The plain HTML way is to put it in a <form>
wherein you specify the desired target URL in the action
attribute.
<form action="https://google.com">
<input type="submit" value="Go to Google" />
</form>
If necessary, set CSS display: inline;
on the form to keep it in the flow with the surrounding text. Instead of <input type="submit">
in above example, you can also use <button type="submit">
. The only difference is that the <button>
element allows children.
You'd intuitively expect to be able to use <button href="https://google.com">
analogous with the <a>
element, but unfortunately no, this attribute does not exist according to HTML specification.
CSS
If CSS is allowed, simply use an <a>
which you style to look like a button using among others the appearance
property (it's only not supported in Internet Explorer).
<a href="https://google.com" class="button">Go to Google</a>
a.button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
text-decoration: none;
color: initial;
}
Or pick one of those many CSS libraries like Bootstrap.
<a href="https://google.com" class="btn btn-primary">Go to Google</a>
JavaScript
If JavaScript is allowed, set the window.location.href
.
<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />
Instead of <input type="button">
in above example, you can also use <button>
. The only difference is that the <button>
element allows children.
Yes, look all tips and tricks with mailto: http://www.angelfire.com/dc/html-webmaster/mailto.htm
mailto subject example:
<a href="mailto:no-one@snai1mai1.com?subject=free chocolate">example</a>
mailto with content:
<a href="mailto:no-one@snai1mai1.com?subject=look at this website&body=Hi,I found this website and thought you might like it http://www.geocities.com/wowhtml/">tell a friend</a>
As alluded to in the comments, both subject
and body
must be escaped properly. Use encodeURIComponent(subject)
on each, rather than hand-coding for specific cases.
As Hoody mentioned in the comments, you can add line breaks by adding the following encoded sequence in the string:
%0D%0A // one line break
Best Answer
You can use URL encoding to encode the newline as
%0A
.mailto:email@address.com?subject=test&body=type%20your%0Amessage%20here
While the above appears to work in many cases, user olibre points out that the RFC governing the mailto URI scheme specifies that
%0D%0A
(carriage return + line feed) should be used instead of%0A
(line feed). See also: Newline Representations.