473,671 Members | 2,287 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 17862
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
12160
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
5098
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
4783
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
4185
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
2606
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
29105
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
10029
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
3906
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
5137
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
8917
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...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7437
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
6229
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
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
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...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.