I'd like to open an email automatically with To & subject, when the html page loads. I need to use only mailto functionality. Can someone help me how to do this?
Redirect the user to a mailto link. This can be done with basic JavaScript:
location.href = "mailto:you#example.com?subject=Test+Message";
Just take into consideration the fact that:
A lot of people use online email these days (GMail, hotmail, etc) - not me personally, but... other people.
If the user has a desktop email program, you'll be forcing an unexpected window open on them.
It's even worse if the user has a desktop email program, but has never set it up - as would be the case of most of the people in point 1. The window would open and then the whole "email setup" process would start.
Just be careful.
try something like this
<html>
<head>
<script type="text/javascript">
function mymessage()
{
location.href = "mailto:you#example.com?subject=Hello";
}
</script>
</head>
<body onload="mymessage()">
</body>
</html>
Related
is there any way to use javascript to open a link in an external program and not(!) in the web browser?
Background: From CRM2015 on-premise i want to open a Mail in Lotus Notes.
script:
<html>
<body>
<p onclick="myFunction()">Click me</p>
<script>
function myFunction() {
window.open("notes:///server/file");
}
</script>
</body>
</html>
What happens: the mail opens in Lotus Notes -> good
But also an additional tab in IE11 occurs, blank page and link in address bar -> bad
What should happen: mail will open in Lotus Notes but no additional tab or windows in IE11.
Is there any way to solve my issue?
Thanks a lot for you help and have a great weekend!
If you want to navigate to an external protocol via JS, do it the same way you'd navigate to a HTTP URL:
function goSomewhere() {
window.location = "notes:///server/file";
}
Sane browsers should 1. stay on the same page, and 2. launch the external program (emphasis on should and no guarantees on insane browsers - e.g. IE8 and below).
Something I've recently done on a few sites I've developed for is to create an included JavaScript function which prints an email address based off of an argument. An example below:
/index.html
...
<head>
<script src="/script/main.js></script>
</head>
<body>
...
<p><script>printEmail('info');</script></p>
...
/script/main.js
function printEmail(a) {
document.write('' + a + '#domain.com');
}
The thought process that I have is that the relatively small script should help deter spambots by not including the email address in full anywhere in the source code. The only place it becomes readable is through the rendering engine.
So is it secure? Also, how secure is it compared to other prevention methods?
If it renders to the page on page load, I don't think this would do anything, since the spam bots would wait for the page to load anyways and then grab the emails.
If you make a user action required, like hovering over the email to reveal the full email, at which point the javascript prints it out, I think that would be more effective, and I've seen things like that in use on pages before.
I need two pages to be open at once when the user clicks on an image that is being sent in an email message.
I tried to use window.open but when the message is sent to the recipient the link on the image does not work.
Could you help me or tell me a better way to make this possible??
The code:
<img width="500" align="center" src="img_1">
Within email app, it's not possible. As Quentin mentioned above, all of the email consumption software, including Outlook, webmail and iPhone native email app will block your JavaScript in the message.
However, in theory, the result could be achieved using an intermediary landing page, which would perform the all the JS you need, opening two tabs.
I once had a similar project where we implemented intermediary landing page that sniffed the user agent and redirected to the deep-linked mobile website or a different desktop landing page. For example, you would link to your landing page like:
http://yourlandingpage.com?tab1toopen=http://page1.com&tab2toopen=http://page2.com
This raises new issues around:
* URL tracking (and automating encoding and/or optional URL shortening and admin of all of this),
* URL length (which is limited on Windows desktop Outlook clients),
* security of that landing page (lander should sanitize the strings, maybe even do some secret hand-shaking via unique encrypted var), and,
* can it sustain the heavy traffic (which is larger problem that it appears if you work with big brands).
Due to major security issues, scripting is not available in emails. Many clients will strip the scripting completely while others can mark it as spam or block it entirely.
Your best bet would be to have it link to a static landing page that then runs a script to open the two windows for you.
http://javascript.about.com/od/reference/a/jsemail.htm
Some other good sources on what is allowed and not allowed in HTML email:
http://kb.mailchimp.com/campaigns/design/limitations-of-html-email
http://kb.mailchimp.com/templates/code/common-html-mistakes
https://www.campaignmonitor.com/dev-resources/guides/coding/
How about this?
HTML
<img width="500" align="center" src="img_1">
JS
<script type="text/javascript">
function DoThis() {
window.open('http://www.foo.com', _blank); //open link 1 in new tab
window.open('http://www.g1.com.br', _blank); //open link 2 in new tab
}
</script>
I was wondering how I would get the name of the current user in JavaScript as part of an HTML document.
In Java, one would type System.getProperty("user.name"); to achieve this. What is the alternative to this in JavaScript?
JavaScript runs in the context of the current HTML document, so it won't be able to determine anything about a current user unless it's in the current page or you do AJAX calls to a server-side script to get more information.
JavaScript will not be able to determine your Windows user name.
There is no fully compatible alternative in JavaScript as it posses an unsafe security issue to allow client-side code to become aware of the logged in user.
That said, the following code would allow you to get the logged in username, but it will only work on Windows, and only within Internet Explorer, as it makes use of ActiveX. Also Internet Explorer will most likely display a popup alerting you to the potential security problems associated with using this code, which won't exactly help usability.
<!doctype html>
<html>
<head>
<title>Windows Username</title>
</head>
<body>
<script type="text/javascript">
var WinNetwork = new ActiveXObject("WScript.Network");
alert(WinNetwork.UserName);
</script>
</body>
</html>
As Surreal Dreams suggested you could use AJAX to call a server-side method that serves back the username, or render the HTML with a hidden input with a value of the logged in user, for e.g.
(ASP.NET MVC 3 syntax)
<input id="username" type="hidden" value="#User.Identity.Name" />
If the script is running on Microsoft Windows in an HTA or similar, you can do this:
var wshshell=new ActiveXObject("wscript.shell");
var username=wshshell.ExpandEnvironmentStrings("%username%");
Otherwise, as others have pointed out, you're out of luck. This is considered to be private information and is not provided by the browser to the javascript engine.
I think is not possible to do that. It would be a huge security risk if a browser access to that kind of personal information
Working for me on IE:
<script type="text/javascript">
var WinNetwork = new ActiveXObject("WScript.Network");
document.write(WinNetwork.UserName);
</script>
...but ActiveX controls needs to be on in security settings.
I found an nice script while searching and inspecting the elements of some websites.
This is what I have found:
<script type="text/javascript">
//redirect browser to fullscreen preview
if (/^http:\/\/codecanyon\.net/.test(document.referrer))
window.top.location.href = 'http://www.gravitysign.com/backslider/';
</script>
So if I understood from this script it tells jquery if the website is opened over codecanyon redirect them to specifed website for preview.
Now... I was wondering if there is possibility to make something like this.
If we specify an website for example http://google.com and we input that into javascript... And then if that website is uploaded to any other domain, other then google.com ... It will redirect to specified site (google) ?
So to clear things out a little bit let me make an example.
If I made a website for "an-website.com" and then someone take their website and upload it to "another-website.com", it will automatically redirect all visitors from another-website.com to an-website.com.
Hope I was clear enough and hope that this is possible. Cheers!
You can of course redirect any user accessing your site from a domain not matching yours but using javascript. This should work just fine:
if (window.location.hostname !== 'yourdomain.com'){
window.top.location.href = 'http://yourdomain.com';
}
You can also use match, if you host your site on a subdomain, etc.
Keep in mind that any person with write access to the file on the server will be able to remove this "copy protection". Copy protecting client side content is impossible, as you need to serve the content in a way a browser understands, effectively making the content available to anyone.
If you are looking for solution for single domain protection, here you can see my
Redirect Website if its not specified domain in script - Protection using Javascript
I am looking for solution for multiple domain.