Happy New Year! I have this bookmarklet but it opens in the same page. How can i force it to open in new tab?
javascript: var lingq_base_url = %27https://www.lingq.com%27;(function()%7B(function()%7Bvar b=function()%7Bwindow.lingq_bookmarklet%3Flingq_bookmarklet():window.setTimeout(b,500)%7D,c=document.getElementsByTagName("head")%5B0%5D,a=document.createElement("script");a.setAttribute("type","text/javascript");a.setAttribute("src",lingq_base_url+"/bookmarklet/bookmarklet.js");c.appendChild(a);b()%7D)()%7D)()
Thanks in advance.
Use window.open funtion for the new tab. See the example below.
window.open(url, '_blank');
Thanks all of you! I think i found my answer i have added window.open(window.location.href, '_blank');
this one at the end of my bookmarklet. It opens the same page and bookmarklet also works. Looks like doing the reverse:)
Try it. I am not sure about your URL.
HTML
<p onclick ="OpenNewTab()">Click Me.</p>
Script
<script>
function OpenNewTab(){
window.open('%27https://www.lingq.com%27;(function()%7B(function()%7Bvar b=function()%7Bwindow.lingq_bookmarklet%3Flingq_bookmarklet():window.setTimeout(b,500)%7D,c=document.getElementsByTagName("head")%5B0%5D,a=document.createElement("script");a.setAttribute("type","text/javascript");a.setAttribute("src",lingq_base_url+"/bookmarklet/bookmarklet.js");c.appendChild(a);b()%7D)()%7D)()','_blank');
}
</script>
The bookmarklet upload the selected text the website (lingq.com)
I have added javascript in front of the your code. Does it must be like that?
javascript: function OpenNewTab(){
window.open('%27https://www.lingq.com%27;(function()%7B(function()%7Bvar b=function()%7Bwindow.lingq_bookmarklet%3Flingq_bookmarklet():window.setTimeout(b,500)%7D,c=document.getElementsByTagName("head")%5B0%5D,a=document.createElement("script");a.setAttribute("type","text/javascript");a.setAttribute("src",lingq_base_url+"/bookmarklet/bookmarklet.js");c.appendChild(a);b()%7D)()%7D)()','_blank');
}
You can use window.open to go to a url.
window.open("www.url.com");
You can also pass few arguments to determine how the url be open.
You can pass there arguments like this.
window.open("www.url.com","_blank");
window.open("www.url.com","_parent ");
window.open("www.url.com","_self ");
window.open("www.url.com","_top");
There are few other parameters that you can use. (specs, replace)
Use this link to read more: https://www.w3schools.com/jsref/met_win_open.asp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.