window.open() Not Opening in Same Window All The Time

K

k.vanderstarren

Hi All,

I'm having a problem that is driving me absolutely batty and I'm hoping
that one of you JavaScript gurus can help me out before I go stark
raving mad.

I am using the function shown below to open links into the same pop-up
window each time a user clicks any of the news story links contained in
http://www.kris.ca/newsroom.aspx. The function works perfectly for all
of the links except for the ones from the BBC's website. Links to
stories from the BBC's website insist on opening in a new popup window
each time no matter what I do. This behaviour is consistent in both IE
and Firefox.

The behaviour makes absolutely no sense to me as all of the links use
the same function call. Any ideas?


function popupfeed(url) {
var myfeatures =
"toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,status=yes,resizable=yes,width=800,height=600";

thefeed = window.open( url, 'feed2jspop', myfeatures);
if (window.focus) {thefeed.focus()}
}
 
K

k.vanderstarren

Thank you for the response Tony. That thought had occurred to me as
well but wouldn't that cause two pop-ups then - one from my code and
another from theirs?
 
R

RobG

Hi All,

I'm having a problem that is driving me absolutely batty and I'm hoping
that one of you JavaScript gurus can help me out before I go stark
raving mad.

I am using the function shown below to open links into the same pop-up
window each time a user clicks any of the news story links contained in
http://www.kris.ca/newsroom.aspx. The function works perfectly for all
of the links except for the ones from the BBC's website. Links to
stories from the BBC's website insist on opening in a new popup window
each time no matter what I do. This behaviour is consistent in both IE
and Firefox.

The behaviour makes absolutely no sense to me as all of the links use
the same function call. Any ideas?


function popupfeed(url) {
var myfeatures =
"toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,status=yes,resizable=yes,width=800,height=600";

thefeed = window.open( url, 'feed2jspop', myfeatures);
if (window.focus) {thefeed.focus()}
}

Try instead:

// Declare window name as a global variable
var feedWindow;

function popupfeed(url)
{

// Open window only if not already open
if (!feedWindow || feedWindow.closed){

// Just include the features you want, the others will be
// off by default (if permitted by browser settings)
var popfeatures =
"menubar,scrollbars,status,resizable,width=800,height=600";

feedWindow = window.open('','feed2jspop','popfeatures');
}

// Set the location
feedWindow.location = url;

// Give it focus
if (feedWindow.focus) feedWindow.focus();

// Allow onclick to stop navigation if A element used
return !feedWindow;
}


Read the stuff here:

<URL:http://developer.mozilla.org/en/docs/DOM:window.open>
 
K

k.vanderstarren

Thank you for the response RobG. Your solution worked like a charm
except that I couldn't I couldn't get the scroll bars to appear ...
which presents a problem if the news story doesn't fit in the 800 x 600
window. Any ideas?
 
K

k.vanderstarren

Please disregard my previous reply ... I got the scroll bars working
now ... stupid typo on my part. :)

The solution is working 99% of the time now but it still opens new
windows occasionally. It's very bizarre, but it seems that a new window
is opened each time you transition from the BBC's news stories to news
stories from any other source. For example, if I display stories from
the BBC, I can click to my hearts content and the stories will stay in
the same pop-up. If, however, the pop-up is open and it contains a
story from the BBC and I try to display a story from any other source
(ABC News for example), the story will open a brand new pop-up. Very
odd to say the least!

Is it possible that the BBC's page contains some javascript that
detects when the window is navigating to a different domain? If so, is
there anyway that I can disable javascript for the link that I am
opening?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,050
Members
48,769
Latest member
Clifft

Latest Threads

Top