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.
Related
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
Edit: The link above doesn't contain any answer that applies to this question. If the person who put it there actually read this question they would have realized this.
What's my best option for opening a link in either a new tab or new window when I only have control over the href attribute of an anchor tag?
We have a homegrown menu navigation system that someone before me built and it sets the href of the menu anchor links based on a url column in a database table. So I know there are much better ways to open a link in a new window than what I'm asking for and I wouldn't normally try this, but for now I just need to do it this way.
I've tried using:
javascript:window.open('http://www.goodwill.org')
That does work for opening the link in a new tab, however it changes the current tab to be a blank page except for the text [object], which obviously defeats the purpose.
You need to ensure that the JS expression in your link does not return a value:
javascript: void(window.open('http://www.goodwill.org'))
If you have access to the html, which you do by either html or js
HTML
<a target="_blank">
Im stumped..... I'm using Fancybox jquery plug in to display some iframes over the top of my page in a lightbox style.... i have it all working but if I try to link to an external website from within the lightbox using the normal somesite
I before you suggest it I have tried target="_blank"with no luck.
it opens in the lightbox not in the original window, I dont mind if it opens in a new tab or windows I just cant have it opening in the lightbox... has anyone else experienced this before?
Just to make sure that I have understood the scenario here -
You have a link that when clicked, opens the content in a fancybox pop-up.
This content has some text and within that, it has a somesite link. You have also tried target="_blank".
When this <a>..</a> is clicked, it should act like a normal link and open in a browser (new tab or window). But it opens the this link in the fancybox pop-up instead.
If that's the case then I tried it and the link opened in a new tab.
Please clarify the above doubt of mine.
Thanks.
Try target="_parent" instead of target="_blank"
See following example:
somesite
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');
i read a lot of solutions but all of them are clicking a url, and it works, but my client ask me to do is users opens his website, it automatically open a new tab with some special offers , so my question, is there any way to open a new tab without any user intervention? , maybe a jquery plugin?, i know the tabs rely on the web browser, but it have to be a way, a lot of web pages does it,but how?
Greetings
Without modifying the configuration of browser, the answer is no, only trusted event can open a new window (or tab)
You may ask if your client could change their browser's configuration to allow a popup window from an untrusted javascript program.
Write script in your page to open new page:
<script>
window.open("specialOffers.aspx");
</script>
and in the "specialOffers.aspx" page in the tag write:
<base target="_blank"/>