473,788 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Click on a link to open it in a new window/tab WITHOUT leaving the current page

Hi,
I've just been scouring the web trying to find an answer for how to do
this but so far without any success.

Basically I want some of the links in my page to open in new tabs (I'm
using Firefox) or windows if the user has their options configured
that way. And I want my page to remain intact as it involves some AJAX
and takes a while to load.

But ...and this seems to be a big "but"... I don't want the focus to
move away from the page I'm on. So techniques such as <a
target="_blank" or <a onclick="window .open(...)"aren 't working for
this requirement. I even tried using a separate function and
attempting to return to the original window straight after using the
following function:

// Open a URL in a new window or tab (depending on browser-specific
settings) and move focus to it
function openLinkInNewWi ndow(link) {
var newWindow = window.open(lin k);
window.opener.f ocus();
}

But in Firefox this is just causing both tabs to open the new link.

So now I'm scratching my head and wondering if it's going to be
possible at all. Is there something I've missed? Thanks a lot for any
help or advice (but please don't condone me for opening these links in
new windows or ask why I want to do it, trust me, I do!!!)

Cheers
Steve

Sep 24 '07 #1
7 17906
On Sep 24, 5:48 pm, chambers.a...@g ooglemail.com wrote:
Hi,
I've just been scouring the web trying to find an answer for how to do
this but so far without any success.

Basically I want some of the links in my page to open in new tabs (I'm
using Firefox) or windows if the user has their options configured
that way. And I want my page to remain intact as it involves some AJAX
and takes a while to load.

But ...and this seems to be a big "but"... I don't want the focus to
move away from the page I'm on. So techniques such as <a
target="_blank" or <a onclick="window .open(...)"aren 't working for
this requirement. I even tried using a separate function and
attempting to return to the original window straight after using the
following function:

// Open a URL in a new window or tab (depending on browser-specific
settings) and move focus to it
function openLinkInNewWi ndow(link) {
var newWindow = window.open(lin k);
window.opener.f ocus();

}

But in Firefox this is just causing both tabs to open the new link.

So now I'm scratching my head and wondering if it's going to be
possible at all. Is there something I've missed? Thanks a lot for any
help or advice (but please don't condone me for opening these links in
new windows or ask why I want to do it, trust me, I do!!!)

Cheers
Steve
Try FF's openNewTabWith( ). If that doesn't work look under the cover
and see if you can get the functionality you're looking for.

Sep 25 '07 #2
On Sep 25, 2:32 am, matth <matt...@gmail. comwrote:
On Sep 24, 5:48 pm, chambers.a...@g ooglemail.com wrote:
Hi,
I've just been scouring the web trying to find an answer for how to do
this but so far without any success.
Basically I want some of the links in my page to open in new tabs (I'm
using Firefox) or windows if the user has their options configured
that way. And I want my page to remain intact as it involves some AJAX
and takes a while to load.
But ...and this seems to be a big "but"... I don't want the focus to
move away from the page I'm on. So techniques such as <a
target="_blank" or <a onclick="window .open(...)"aren 't working for
this requirement. I even tried using a separate function and
attempting to return to the original window straight after using the
following function:
// Open a URL in a new window or tab (depending on browser-specific
settings) and move focus to it
function openLinkInNewWi ndow(link) {
var newWindow = window.open(lin k);
window.opener.f ocus();
}
But in Firefox this is just causing both tabs to open the new link.
So now I'm scratching my head and wondering if it's going to be
possible at all. Is there something I've missed? Thanks a lot for any
help or advice (but please don't condone me for opening these links in
new windows or ask why I want to do it, trust me, I do!!!)
Cheers
Steve

Try FF's openNewTabWith( ). If that doesn't work look under the cover
and see if you can get the functionality you're looking for.
Thanks for your reply matth but Firefox-specific code isn't really an
option here as I need this to work in all (recent) browsers.

Sep 25 '07 #3
ch***********@g ooglemail.com wrote:
Basically I want some of the links in my page to open in new tabs (I'm
using Firefox) or windows if the user has their options configured
that way. And I want my page to remain intact as it involves some AJAX
and takes a while to load.

But ...and this seems to be a big "but"... I don't want the focus to
move away from the page I'm on.
Tough luck. Focus windows is under the control of the user, too. Firefox
has a preference for this (dom.disable_wi ndow_flip), and a UI for that:
Tools, Options, Content, Raise or lower windows. The default is `true'
(the checkbox is unchecked), meaning that Firefox does not allow that.
[...]
// Open a URL in a new window or tab (depending on browser-specific
settings) and move focus to it
Either the description above or this description is wrong. From the above,
I take it that you _don't_ want to focus the new window or tab. Assuming
this is what you actually want to achieve:
function openLinkInNewWi ndow(link) {
var newWindow = window.open(lin k);
window.opener.f ocus();
`window' does not refer to the last opened window/tab (that is what
`newWindow' refers to here), but to the *current* window/tab. You are
looking for

window.focus();

instead. The usual feature tests should be applied.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Sep 25 '07 #4
Thomas 'PointedEars' Lahn wrote:
ch***********@g ooglemail.com wrote:
>Basically I want some of the links in my page to open in new tabs (I'm
using Firefox) or windows if the user has their options configured
that way. And I want my page to remain intact as it involves some AJAX
and takes a while to load.

But ...and this seems to be a big "but"... I don't want the focus to
move away from the page I'm on.

Tough luck. Focus windows is under the control of the user, too. Firefox
has a preference for this (dom.disable_wi ndow_flip), and a UI for that:
Tools, Options, Content, Raise or lower windows.
Tools, Options, Content, [x] Enable JavaScript, "Advanced.. .", (Scripts will
be allowed to do the following:) Raise or lower windows.
The default is `true' (the checkbox is unchecked), meaning that Firefox
does not allow that.
Sep 25 '07 #5
matth wrote:
Try FF's openNewTabWith( ). [...]
| >>openNewTabWit h("http://example.net/")
| [Error:] openNewTabWith is not defined
|
| >>window.openNe wTabWith("examp le.net/")
| [Error:] window.openNewT abWith is not a function
|
| >>navigator.use rAgent
| "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7
| Gecko/20070914 Firefox/2.0.0.7"

JFYI: This method is available to native Gecko code and (Firefox)
add-ons, not to unprivileged JavaScript. And that is good so.

http://developer.mozilla.org/en/docs...indow.open#FAQ
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Sep 25 '07 #6
Hi PointedEars,
First thanks for the replies but unfortunately it seems I'm no nearer
to where I need to be...see below.
Cheers, Steve

On Sep 25, 8:23 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
chambers.a...@g ooglemail.com wrote:
[...]
// Open a URL in a new window or tab (depending on browser-specific
settings) and move focus to it

Either the description above or this description is wrong. From the above,
I take it that you _don't_ want to focus the new window or tab. Assuming
this is what you actually want to achieve:
Yes you're right, the description was wrong. This was left over from
previous functionality where the new window did get the focus but as
you rightly guessed I now want to keep the focus on the original page.
function openLinkInNewWi ndow(link) {
var newWindow = window.open(lin k);
window.opener.f ocus();

`window' does not refer to the last opened window/tab (that is what
`newWindow' refers to here), but to the *current* window/tab. You are
looking for
window does seem to refer to the tab that has just been opened since
the focus switches to it immediately. However, as mentioned, using
this method I am finding that the new page loads in both tabs (i.e. in
the "spawned" tab and the "opener" tab.) Even if I add an extra line
newWindow.focus () to guarantee that the focus on the new window, this
makes no difference in practice and the same thing happens.

>
window.focus();

instead. The usual feature tests should be applied.
As mentioned, window refers to the new tab at this point so this
doesn't work - I've tested it and find that the line has no effect.

Sep 25 '07 #7
On Sep 25, 1:21 pm, chambers.a...@g ooglemail.com wrote:
On Sep 25, 8:23 am, Thomas 'PointedEars' Lahn wrote:
<snip>
>>function openLinkInNewWi ndow(link) {
var newWindow = window.open(lin k);
window.opener.f ocus();
>`window' does not refer to the last opened window/tab (that is what
`newWindow' refers to here), but to the *current* window/tab.
You are looking for

window does seem to refer to the tab that has just been opened
since the focus switches to it immediately.
Seeming and being are not the same thing.
However, as mentioned, using this method I am finding that
the new page loads in both tabs (i.e. in the "spawned" tab
and the "opener" tab.)
The error that is likely to be generated when you attempt to execute -
window.opener.f ocus() - on a page that has no - opener - may explain
that symptom.
Even if I add an extra line newWindow.focus () to guarantee
that the focus on the new window, this makes no difference
in practice and the same thing happens.
Did you add that before or after the line that is generating an error?
> window.focus();
>instead. The usual feature tests should be applied.

As mentioned, window refers to the new tab at this point
No it does not.
so this doesn't work - I've tested it and find that the line
has no effect.
Do you mean that line has no effect at all (and if window/tab focusing
by scripts is being restricted in the browser it can be expected to
have no effect anyway) or that is has no effect alongside the error
producing line.

Sep 25 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12178
by: lukeo | last post by:
I'm shelling out to an .asp (or htm) page from an application. I want to show this in a window without the address bar, etc... Is there a way I can redirect this page using javascript to a page where I can set the window height, statusbar=no, etc? Thanks, -Luke
8
5109
by: timmy_dale12 | last post by:
I need help with this one. I have a function that pastes a row. In each row i am pasting a link which is to call a date picker javascript function. This is the code that pastes the link : link = document.createElement('a'); link.href ="javascript:show_calendar('document.form1.date',document.form1.date.value);"; img = document.createElement('img'); img.setAttribute("src","H:Diverse\\cal.gif"); link.appendChild(img);
4
4804
by: yfng | last post by:
In a web form, I want the user clicks on one button and this button will trigger another button/link which will open a new browser window? How to do that? Is there any method like Button.performclick? Thanks
2
4193
by: cschang | last post by:
I have a form containing a link next to an input box. I include a javascript function in the input by using the onblur='fuc()'. I used this function to open another ASP page to do something and then close the window. There was no problem if I just clicked other place on the form. everything was working as charm. However, If I want to click the link next to it after I moved out the input box, I always have to click twice in order to...
2
2614
by: yatharth | last post by:
I am facing a problem ,the situation is like this. I have a home page named "Index.html" ,on which there is login link,when i click on the login link the login popup opens and user enter the login information in it. Now when the user click the submit button then new popup window
3
29109
by: hb | last post by:
Hi, I have a asp:button btnGo. When clicking this button, the code will parse a asp:table to find a specific ID under certain conditions. Once the ID is found, the code need to keep the current page open and to redirect the user to a newly opened browser window with a link like: http://www.mydomain.com/tellme.aspx?clientID="+ID But the Response.Redirect(URL) opens a new page in the same
3
10071
by: Sameer | last post by:
I have a webpage that has a link button. This link button on click opens up a new page. This is what is happening: 1. Load the web page. 2. Click on the link. 3. Refresh the web-page. Result: The webpage gets refreshed and the link buttons onClick event is fired.
31
3928
by: TC | last post by:
I'm looking for opinions on ways to show visitors, your links will send them off-site (to another website). The following was suggested: Look at the three links under the third paragraph: http://www.countryrode.com/sales/vespaline.php Note the tooltip when hovering the graphic as well. Personally, I have not seen these. Are they really needed? Do users care they are being directed off your site?
6
5145
by: bnashenas1984 | last post by:
Here you can see the script I found in google to refresh a page without hearing any click sound which is usual to hear when a link is clicked or a page is refreshed. <script type="text/javascript" > window.onload = doLoad; function doLoad() { setTimeout( "refresh()", 5*1000 );
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.