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

Discussion in 'Javascript' started by k.vanderstarren@gmail.com, Apr 14, 2006.

  1. Guest

    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()}
    }
     
    , Apr 14, 2006
    #1
    1. Advertising

  2. Guest

    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?
     
    , Apr 15, 2006
    #2
    1. Advertising

  3. RobG Guest

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



    --
    Rob
     
    RobG, Apr 15, 2006
    #3
  4. Guest

    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?
     
    , Apr 18, 2006
    #4
  5. Guest

    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?
     
    , Apr 18, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. flamesrock
    Replies:
    8
    Views:
    519
    Hendrik van Rooyen
    Nov 24, 2006
  2. Larry Bud

    Opening a window in the same session

    Larry Bud, Mar 1, 2006, in forum: ASP General
    Replies:
    3
    Views:
    143
    Mike Brind
    Mar 2, 2006
  3. Jess
    Replies:
    4
    Views:
    138
    Bob Barrows [MVP]
    Apr 11, 2006
  4. Replies:
    21
    Views:
    476
    Daniel Crichton
    Jan 19, 2009
  5. Danny
    Replies:
    1
    Views:
    134
    Robert
    Sep 15, 2004
Loading...

Share This Page