1

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.

random_user_name
  • 25,694
  • 7
  • 76
  • 115
speedyy
  • 27
  • 5
  • 2
    Welcome. Your code appears to be copy-paste from something that has injected character encoding. Can you please copy / paste from your original script code? – random_user_name Dec 31 '18 at 23:50
  • 1
    Possible duplicate of [JavaScript: location.href to open in new window/tab?](https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab) – Heretic Monkey Jan 01 '19 at 01:07

5 Answers5

1

Use window.open funtion for the new tab. See the example below.

window.open(url, '_blank');
maazadeeb
  • 5,922
  • 2
  • 27
  • 40
Arman sheikh
  • 176
  • 2
  • 7
1

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:)

speedyy
  • 27
  • 5
0

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>
Majedur
  • 3,074
  • 1
  • 30
  • 43
0

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');
}
speedyy
  • 27
  • 5
0

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.

  • _blank - URL is loaded into a new window. This is default
  • _parent - URL is loaded into the parent frame
  • _self - URL replaces the current page
  • _top - URL replaces any framesets that may be loaded

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

Nouman Dilshad
  • 1,014
  • 13
  • 16