Javascript window.open fails in IE

Discussion in 'Javascript' started by gleverett@gmail.com, Sep 19, 2005.

  1. Guest

    I have been searching the 'Net, and I can't find the right solution
    here. I am writing some PHP pages that utilize some Javascript. The
    script works in Mozilla/Netscape, but fails in IE. I don't know if
    it's the Javascript or the PHP that is causing the problem. I started
    with an example in a book and added on.

    The script I'm using is:

    <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    <!--
    function open_window(url) {
    var NEW_WIN = null;
    NEW_WIN = window.open ("", "Record Viewer", "toolbar=no,width=<?php
    echo $new_win_width ?>,height=<?php echo new_win_height
    ?>,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    NEW_WIN.location.href = url;
    }

    //-->
    </SCRIPT>

    (I added some line break to make it readable The NEW_WIN line is all
    on one line.)

    The PHP variables get added correctly, and the two calls from the PHP
    program are similar to:

    <a
    href="javascript:eek:pen_window('$PHP_SELF?action=action1');\">Action1</a>

    or an

    echo "<button
    onClick=\"javascript:eek:pen_window('$PHP_SELF?action=insert_record');\" >
    Insert new record</button>";

    These work fine in Netscape/Mozilla, but in IE, after clickng a bunch
    of times, I get "Domain not found". I've replaced PHP_SELF with the
    full URL to test, and it still fails. I know that the scripting is
    turned on in IE becuase I can go to example sites and the window.open
    function works.

    Any ideas as to what's going on here?
     
    , Sep 19, 2005
    #1
    1. Advertising

  2. Randy Webb Guest

    said the following on 9/19/2005 4:11 PM:

    > I have been searching the 'Net, and I can't find the right solution
    > here. I am writing some PHP pages that utilize some Javascript. The
    > script works in Mozilla/Netscape, but fails in IE. I don't know if
    > it's the Javascript or the PHP that is causing the problem. I started
    > with an example in a book and added on.
    >
    > The script I'm using is:
    >
    > <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    > <!--
    > function open_window(url) {
    > var NEW_WIN = null;
    > NEW_WIN = window.open ("", "Record Viewer", "toolbar=no,width=<?php


    IE is known not to handle window names with spaces in them real well.
    Change it to "RecordViewer" or "Record_Viewer"

    > echo $new_win_width ?>,height=<?php echo new_win_height
    > ?>,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    > NEW_WIN.location.href = url;
    > }
    >
    > //-->
    > </SCRIPT>


    Post the code that gets sent to the browser, not the PHP code that
    generates it. And why are you opening a blank window and then setting
    it's href property? Just specify the URL in the window.open call:

    window.open(url,"Record Viewer",.....)

    > <a
    > href="javascript:eek:pen_window('$PHP_SELF?action=action1');\">Action1</a>


    http://jibbering.com/faq/#FAQ4_24

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Sep 19, 2005
    #2
    1. Advertising

  3. McKirahan Guest

    <> wrote in message
    news:...
    > I have been searching the 'Net, and I can't find the right solution
    > here. I am writing some PHP pages that utilize some Javascript. The
    > script works in Mozilla/Netscape, but fails in IE. I don't know if
    > it's the Javascript or the PHP that is causing the problem. I started
    > with an example in a book and added on.
    >
    > The script I'm using is:
    >
    > <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    > <!--
    > function open_window(url) {
    > var NEW_WIN = null;
    > NEW_WIN = window.open ("", "Record Viewer", "toolbar=no,width=<?php
    > echo $new_win_width ?>,height=<?php echo new_win_height
    > ?>,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    > NEW_WIN.location.href = url;
    > }
    >
    > //-->
    > </SCRIPT>
    >
    > (I added some line break to make it readable The NEW_WIN line is all
    > on one line.)
    >
    > The PHP variables get added correctly, and the two calls from the PHP
    > program are similar to:
    >
    > <a
    > href="javascript:eek:pen_window('$PHP_SELF?action=action1');\">Action1</a>
    >
    > or an
    >
    > echo "<button
    > onClick=\"javascript:eek:pen_window('$PHP_SELF?action=insert_record');\" >
    > Insert new record</button>";
    >
    > These work fine in Netscape/Mozilla, but in IE, after clickng a bunch
    > of times, I get "Domain not found". I've replaced PHP_SELF with the
    > full URL to test, and it still fails. I know that the scripting is
    > turned on in IE becuase I can go to example sites and the window.open
    > function works.
    >
    > Any ideas as to what's going on here?



    I tested with this variation:

    <html>
    <head>
    <title>js_php.htm</title>
    <script type="text/javascript">
    function open_window(url) {
    var cfg = "width=<?php echo $new_win_width ?>,"
    cfg += "height=<?php echo new_win_height ?>,";
    cfg += "scrollbars=yes,resizable=yes"
    var win = window.open ("","Record Viewer",cfg);
    win.location.href = url;
    }
    </script>
    </head>
    <body onload="open_window('http://www.google.com/')">
    </body>
    </html>

    and it didn't work for me under IE (5.5) either.

    My guess is that IE doesn't interpret inline php.
     
    McKirahan, Sep 19, 2005
    #3
  4. Randy Webb Guest

    McKirahan said the following on 9/19/2005 5:56 PM:
    > <> wrote in message
    > news:...
    >
    >>I have been searching the 'Net, and I can't find the right solution
    >>here. I am writing some PHP pages that utilize some Javascript. The
    >>script works in Mozilla/Netscape, but fails in IE. I don't know if
    >>it's the Javascript or the PHP that is causing the problem. I started
    >>with an example in a book and added on.
    >>
    >>The script I'm using is:
    >>
    >><SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    >><!--
    >> function open_window(url) {
    >>var NEW_WIN = null;
    >>NEW_WIN = window.open ("", "Record Viewer", "toolbar=no,width=<?php
    >> echo $new_win_width ?>,height=<?php echo new_win_height
    >>?>,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    >>NEW_WIN.location.href = url;
    >>}
    >>
    >>//-->
    >></SCRIPT>
    >>
    >>(I added some line break to make it readable The NEW_WIN line is all
    >>on one line.)
    >>
    >>The PHP variables get added correctly, and the two calls from the PHP
    >>program are similar to:
    >>
    >><a
    >>href="javascript:eek:pen_window('$PHP_SELF?action=action1');\">Action1</a>
    >>
    >>or an
    >>
    >>echo "<button
    >>onClick=\"javascript:eek:pen_window('$PHP_SELF?action=insert_record');\" >
    >>Insert new record</button>";
    >>
    >>These work fine in Netscape/Mozilla, but in IE, after clickng a bunch
    >>of times, I get "Domain not found". I've replaced PHP_SELF with the
    >>full URL to test, and it still fails. I know that the scripting is
    >>turned on in IE becuase I can go to example sites and the window.open
    >>function works.
    >>
    >>Any ideas as to what's going on here?

    >
    >
    >
    > I tested with this variation:
    >
    > <html>
    > <head>
    > <title>js_php.htm</title>
    > <script type="text/javascript">
    > function open_window(url) {
    > var cfg = "width=<?php echo $new_win_width ?>,"
    > cfg += "height=<?php echo new_win_height ?>,";
    > cfg += "scrollbars=yes,resizable=yes"
    > var win = window.open ("","Record Viewer",cfg);
    > win.location.href = url;
    > }
    > </script>
    > </head>
    > <body onload="open_window('http://www.google.com/')">
    > </body>
    > </html>
    >
    > and it didn't work for me under IE (5.5) either.
    >
    > My guess is that IE doesn't interpret inline php.


    Since php is processed on the server (with an exception and that is a
    plugin that allows php to be clientside), whether IE interprets it or
    not is totally dependent on whether PHP is enabled on the server. Try
    changing your window name to no spaces, remove the PHP code, and see
    what happens.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?
     
    Randy Webb, Sep 19, 2005
    #4
  5. a écrit :
    > I have been searching the 'Net, and I can't find the right solution
    > here. I am writing some PHP pages that utilize some Javascript. The
    > script works in Mozilla/Netscape, but fails in IE. I don't know if
    > it's the Javascript or the PHP that is causing the problem. I started
    > with an example in a book and added on.
    >
    > The script I'm using is:
    >
    > <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">


    language attribute is deprecated.

    > <!--


    HTML comment is not needed here.

    > function open_window(url) {
    > var NEW_WIN = null;
    > NEW_WIN = window.open ("", "Record Viewer", "toolbar=no,width=<?php


    Right here. The window name should be a one string without blank space.

    http://developer.mozilla.org/en/docs/DOM:window.open


    > echo $new_win_width ?>,height=<?php echo new_win_height
    > ?>,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")


    If the windowFeatures string list is not empty, then you only need to
    set the features which will be on, enabled.

    ;
    > NEW_WIN.location.href = url;


    I never understood why people code like that. Why not define the url in
    the window.open() call?

    > }
    >
    > //-->
    > </SCRIPT>
    >
    > (I added some line break to make it readable The NEW_WIN line is all
    > on one line.)
    >
    > The PHP variables get added correctly, and the two calls from the PHP
    > program are similar to:
    >
    > <a
    > href="javascript:eek:pen_window('$PHP_SELF?action=action1');\">Action1</a>
    >



    "javascript:" pseudo-protocol is definitely not recommendable.

    http://jibbering.com/faq/#FAQ4_24

    http://developer.mozilla.org/en/doc...D.22javascript:window.open.28....29.22_....3E
    "
    * "javascript:" pseudo-links become dysfunctional when javascript
    support is disabled or inexistent. Several corporations allow their
    employees to surf on the web but under strict security policies: no
    javascript enabled, no java, no activeX, no Flash. For various reasons
    (security, public access, text browsers, etc..), about 8% to 12% of
    users on the web surf with javascript disabled.
    * "javascript:" links will interfere with advanced features in
    tab-capable browsers: eg. middle-click on links, Ctrl+click on links,
    tab-browsing features in extensions, etc.
    * "javascript:" links will interfere with the process of indexing
    webpages by search engines.
    * "javascript:" links also interfere with assistive technologies
    and several web-aware applications (e.g. PDA).
    * Protocol scheme "javascript:" will be reported as an error by
    link validators and link checkers.
    "

    Gérard
    --
    remove blah to email me
     
    Gérard Talbot, Sep 20, 2005
    #5
  6. McKirahan a écrit :

    > var win = window.open ("","Record Viewer",cfg);


    var win = window.open (url, "RecordViewer", cfg);

    will work without a problem.



    > win.location.href = url;
    > }
    > </script>
    > </head>
    > <body onload="open_window('http://www.google.com/')">



    Well, first of all, don't try on an onload event.


    > </body>
    > </html>
    >
    > and it didn't work for me under IE (5.5) either.
    >


    Remove the blank space between the word Record and Viewer.

    http://developer.mozilla.org/en/docs/DOM:window.open

    Gérard
    --
    remove blah to email me
     
    Gérard Talbot, Sep 20, 2005
    #6
  7. G-Man Guest

    Thanks to all the suggestions. It turned to be the space in the window
    name.

    To be complete, here is the code that is sent to the browser (minus the

    PHP, and after the change to an "_" in the window name):

    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    <!--
    function open_window(url) {
    var NEW_WIN = null;
    NEW_WIN = window.open ("", "Record_Viewer",
    "toolbar=no,width=850,height=575,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    NEW_WIN.location.href = url;
    }

    //-->
    </SCRIPT>

    I made an example page to test an inline href javascript call like I
    listed in the code above, and a full url. Those continued to fail in
    IE, but after replacing the space with an underscore, all of the links
    worked. I can't belive it's something that simple as a space.

    Thanks! This has been racking my brain for about a week!
     
    G-Man, Sep 20, 2005
    #7
  8. Mick White Guest

    G-Man wrote:
    > Thanks to all the suggestions. It turned to be the space in the window
    > name.
    >
    > To be complete, here is the code that is sent to the browser (minus the
    >
    > PHP, and after the change to an "_" in the window name):
    >
    > <HTML>
    > <HEAD>
    > <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    > <!--
    > function open_window(url) {
    > var NEW_WIN = null;
    > NEW_WIN = window.open ("", "Record_Viewer",
    > "toolbar=no,width=850,height=575,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    > NEW_WIN.location.href = url;
    > }
    >
    > //-->
    > </SCRIPT>

    You have ignored some good advice, here's how I would do it:
    <SCRIPT TYPE="text/javascript">
    function open_window(url) {
    var NEW_WIN = null;//questionable
    NEW_WIN =
    window.open(url,"Record_Viewer","width=850,height=575,scrollbars,resizable");
    }
    </SCRIPT>
     
    Mick White, Sep 20, 2005
    #8
  9. G-Man a écrit :
    > Thanks to all the suggestions. It turned to be the space in the window
    > name.
    >
    > To be complete, here is the code that is sent to the browser (minus the
    >
    > PHP, and after the change to an "_" in the window name):
    >
    > <HTML>
    > <HEAD>
    > <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">


    Again, why do you use language? language is deprecated.

    > <!--


    Why do you need to comment the HTML code? It's not needed anymore.

    > function open_window(url) {
    > var NEW_WIN = null;
    > NEW_WIN = window.open ("", "Record_Viewer",
    > "toolbar=no,width=850,height=575,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
    > NEW_WIN.location.href = url;


    Why not insert the url in the 1st parameter of the window.open()
    function? instead of adding another instructions just to do that...
    You do not need to set the config parameters to no once there is at
    least 1 parameter defined.
    You set the height to 575 but this will not be carried out by a large
    majority of browsers (even users with a 1024x768 scr.res.) because there
    won't be enough height on the user workarea for applications. So, your
    code will trigger error correction mechanisms in MSIE 6, Mozilla-based
    browsers and most likely other browsers.


    > Thanks! This has been racking my brain for about a week!



    Everything was already mentioned at this page:

    http://developer.mozilla.org/en/docs/Gecko_DOM_Reference

    along with best recommendations, examples, etc..

    Gérard
    --
    remove blah to email me
     
    Gérard Talbot, Sep 21, 2005
    #9
  10. Mick White a écrit :

    > <SCRIPT TYPE="text/javascript">
    > function open_window(url) {
    > var NEW_WIN = null;//questionable


    You're absolutely correct. Declaring NEW_WIN as a local variable is
    useless and pointless. It should be a global variable.

    > NEW_WIN =
    > window.open(url,"Record_Viewer","width=850,height=575,scrollbars,resizable");
    >
    > }
    > </SCRIPT>


    Gérard
    --
    remove blah to email me
     
    Gérard Talbot, Sep 21, 2005
    #10
    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. RJN
    Replies:
    1
    Views:
    8,754
    Patrik Löwendahl [C# MVP]
    Oct 10, 2004
  2. ml
    Replies:
    0
    Views:
    1,458
  3. ml
    Replies:
    2
    Views:
    4,862
    John C. Bollinger
    Nov 30, 2004
  4. PC HUA
    Replies:
    2
    Views:
    427
    PC HUA
    May 19, 2004
  5. IveCal
    Replies:
    0
    Views:
    177
    IveCal
    Apr 2, 2007
Loading...

Share This Page