...

View Full Version : please help make this code open in new tab



jonopa
02-27-2012, 12:03 PM
just started learning scripting.

This bookmarklet essentially takes the domain name of the tab currently open when one pressses it & runs a search query through Google prefixing the related: search operator.

As evident, here it shows the result in the same page replacing the earlier one. I would like it to open in a new tab. Can you please tell me how to do so. Self-learning it. At an initial stage of learning, I am.



javascript:location.href='https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host)

Philip M
02-27-2012, 12:49 PM
Whether a page opens in a new window or a new tab is dependent on the user's browser settings. You cannot control that.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

jonopa
02-27-2012, 01:14 PM
Whether a page opens in a new window or a new tab is dependent on the user's browser settings. You cannot control that.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
can i at least instruct it to open in a new tab, if the user's browser permits it.

This code, currently, won't so even if the browser settings permits it

Lerura
02-27-2012, 01:55 PM
javascript:window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank');

If it opens in a tab, a window, or opens at all, depends on users browser settings

jonopa
02-27-2012, 05:04 PM
javascript:window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank');

If it opens in a tab, a window, or opens at all, depends on users browser settings
Hi,
Thanks. While it does open up the result in a new tab, it also changes the original page.
On the page [not the result page], it reads


[object Window]

and in the address bar


javascript:window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank');
i have to press the back key to go back. I would like the initial page to remain unchanged, only the result must appear in a new table

Lerura
02-27-2012, 08:39 PM
Hi,
Thanks. While it does open up the result in a new tab, it also changes the original page.
On the page [not the result page], it reads

and in the address bar


javascript:window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank');
i have to press the back key to go back. I would like the initial page to remain unchanged, only the result must appear in a new table

Sorry! It is on me!
Use this instead:
<a href="void()" onclick="window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank'); return false">LinkText</a>

jonopa
02-28-2012, 04:56 AM
Sorry! It is on me!
Use this instead:
<a href="void()" onclick="window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank'); return false">LinkText</a>


nopes, not working. this one doesn't do anything. the javascript is to be used in the browser toolbar

Lerura
02-28-2012, 05:54 AM
This should work then:
javascript:newwin=function(){window.open('https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host),'_blank');};newwin;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum