I need to use window.location.href to open the user's email so for that I have the following code:
$("#email").click(function(){
window.location.href = "mailto:myemail.com?subject=Subject&body=xxxxxxxxxxxxxxxxxxxxxxxxxxx";
});
Which works fine. However, the problem is I cannot open the user email page in a new tab and it opens by redirecting the current page which is not user friendly. How can I achieve this?
You can use the target="_blank" attribute on any regular anchor tag to make sure that the link is opened in a new tab, without using any JavaScript. Note, however, that mailto links are often handled by browsers specially and may just redirect to the system's default mail app without opening a visible tab.
<a id="email" target="_blank" href="mailto:person#example.com?subject=Subject&body=Body">
Email us!
</a>
Edit: It looks as if this method won't work in certain versions of Firefox, due to a bug. (See this answer.)
You're looking for window.open()
Example:
window.open("mailto:myemail.com?subject=Subject&body=xxxxxxxxxxxxxxxxxxxxxxxxxxx");
Have a look at this:
Open the href mailto link in new tab / window
You can't open a 'mailto' link in new tab/window by default.
You need to use window.open() in your click override.
please check below link and you can view the demo using this link.
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
Related
I have a problem of redirection on tags my angular application (version 11).
When I left click on the link, the redirection is done correctly.
When I do a ctrl+left click it's ok too.
However when I right click and "open in a new tab" then this new tab does not redirect to the expected link but to the home page of my application.
redirectTo() {
window.open("https://www.mylink.com");
}
<a (click)="redirectTo()">My link</a>
Do you have a solution?
Thanks
This is achievable with plain HTML
My link
Or even better to create a directive for external url.
You will add the target to your window.open function
window.open("https://www.link.com", '_blank');
If you wanted to achieve this using HTML only
Link
No but I don't want to force the opening in a second tab. I want to give the user the possibility to open it in a second tab by right-clicking "open in a second tab".
I have a web application where I have four/five icons in the default page. On click of these icons i am redirecting to some URL in new tab of already opened chromium browser instance using javascript. Below is the javascript code snippet that I am using to launch the URL in new tab of already opened chromium browser instance. Here I am manually clicking the icon
window.open(myURL, '_blank');
But the issue is when I am trying to open the same URL using the same code and programatically triggering the same code to open the URL in new tab, it opes up as a Pop Up but not in a tab. Below is how I am trying to pragmatically open the URL. I am calling the click event of the Icon in the default page using some script rather than manually clicking the icon.
$('#myIconId').click();
If somebody could please help me out. TIA
give a try to use
content of the anchor
Although You shouldn't force user to open new pages or new tab without showing them a hint on what is going to happen before they click on the link.
Above code may or may not work on all browser, please test before making live.
UPDATE
Ref : Programmatically open new pages on Tabs
I search a lot but could not figured it out.
Is it possible to open a new window with tab enabled using window.open() method?.
The way chrome context menu "open link in new window" works.
The browser decides on its own how links will open. Sometimes a user can configure how links are to be opened, but the web page cannot do this.
using an anchor tag you can set the target attribute to have some control over where the link opens. Other than that, this behavior is up to the browser and user and cannot be controlled by javascript.
Use this code
window.open("http:.//www.google.com","DemoName",'scrollbars=1,height=650,width=1050');
Using the AddThis plugin (http://www.addthis.com/) I am using the code below to put an email button on my website. But despite setting the target="_blank" it still opens a new tab rather than window. So I am wondering if there is a way to make it open up in a new browser window and not a tab.
<a target="_blank" href="http://api.addthis.com/oexchange/0.8/forward/email/offer? url=${siteURL}/${ourURL}&title=${addThisEmailTitle}" rel="nofollow"><img border="none" src="http://cache.addthiscdn.com/icons/v1/thumbs/email.gif"></img></a>
It all depends on the user and his or her browser defaults.
For example in Chrome target="_blank" opens in a new tab.
The target attribute doesn't help you. AddThis uses a modal pop-up to open the e-mail and other share services (eg. Pinterest). You can use the Addthis Sharing Endpoints that doesn't uses their script and make it work how you want.
Normally we can specify a target in the link or use javascript window.open to open a new window.
But when I access this site
www.wenxuecity.com (It is a chinese site)
I could't find out how it opens each news in a new window.
no target in the link.
debug javascript doesn't show any call to window.open
Could someone tell me how it is implemented?
Thanks
It has this code in the head section:
<base target="_blank">
That sets the default target for all links on the page.