SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.open(URL,name,specs,replace) Issue with IE9

    Hello Every one

    Im using window.open(URL,name,specs,replace) to open a new page
    it works fine with Chrome V22 and Firefox 12
    But when i use it with IE9 it gives me a strange behavior

    When i click it open a new page but the original page changes to the main root of the file index

    Did anyone face such a problem

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newguy99 View Post
    When i click it open a new page but the original page changes to the main root of the file index
    You may be having a side-effect from how you're doing it, and possibly from the web browser performing the default behaviour for a link.

    In other words, please show us the HTML and JavaScript for what you're doing.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well this is the code i used

    Code JavaScript:
    function open_win(id, sub_id)
    {
    window.open('open_att_form.php?level=' + id + '&sub_id=' + sub_id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=660, height=500");
    }

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newguy99 View Post
    Well this is the code i used

    Code JavaScript:
    function open_win(id, sub_id)
    {
    window.open('open_att_form.php?level=' + id + '&sub_id=' + sub_id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=660, height=500");
    }
    And what are you doing to call that function?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a onclick="open_win(1,7)" href="">Add<img src="layout/add.png" alt=""/></a>
    <a onclick="open_win(1,8)" href="">Add<img src="layout/add.png" alt=""/></a>
    <a onclick="open_win(1,9)" href="">Add<img src="layout/add.png" alt=""/></a>

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Okay, so there's the problem. The web browser' default action is not being cancelled anywhere. Return false from the open_win function to prevent the web browser from performing its default action when you click on the link, so that it is only the scripting that performs your desired action instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul
    I did this
    Code:
    function open_win(id, sub_id)
    {
    	window.open('open_att_form.php?level=' + id + '&sub_id=' + sub_id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=660, height=500");
    	
    	return false;
    }
    Still it did not work!
    What im doing wrong.....

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newguy99 View Post
    Still it did not work!
    What im doing wrong.....
    The other thing that's not right is that the href attribute is empty. When it's empty the page reloads. With something in there, commonly "#", no such trouble occurs.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code and IE Version

    My IE Version 9.0.8112
    Update Version 9.0.10

    Code:
    JS Code
    
    <script type="text/javascript">
    function open_win(id, sub_id)
    {
    	window.open('open_att_form.php?level=' + id + '&sub_id=' + sub_id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=660, height=500");
    	
    	return false;
    }
    </script>
    
    
    HTML Code
    
    <a onclick="open_win(1,5)" href="">Add<img src="img/layout/add.png" alt=""/></a>

    Update::::::

    Now i get it BUT what should i do?
    Im using JS to send the data not the link it self.....

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newguy99 View Post
    Now i get it BUT what should i do?
    You need to fix the href attribute of your link. When the href attribute is empty, it causes the page to reload. This occurs regardless of whether you use scripting or not.

    When you intend for the link to be controlled with scripting, you should use "#" for the link instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must return the handler's return value:

    Code:
    <a onclick="return open_win(1,5)" href="">Add<img src="img/layout/add.png" alt=""/></a>
    Tab-indentation is a crime against humanity.

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    You must return the handler's return value
    Aha! That's the missing bit of the puzzle. Thanks for helping to spot that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •