Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    javascript new window

    I currently have my code set to this:

    Code:
    <a href=\"javascript:if(confirm('Are you sure this offer is not working and wish to report it?;?')){document,location.href='report.php?offername=".$row['name']."&offerid=".$row['offerid']."';}\">Report</a>
    How would I make it so that:
    1. It opens in a new window (target="_blank")??
    2. I can define how big that window is

    Thanks

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    You can't. Whether a page opens in a new tab, a new window or not at all is determined by the settings in the user's browser.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by markman641 View Post
    How would I make it so that:
    1. It opens in a new window (target="_blank")??
    2. I can define how big that window is

    Thanks
    1.

    You can open a new window using window.open(). Also, nowadays it is generally considered bad practice to run javascript from a href attribute. Href's are meant for navigating to another another url and not for running javascript.

    Best practice nowadays is to do something like this:

    Code:
    <a href="" onclick="runMyJsFunction(); return false;">Click me</a>
    The return false; aborts the default action of the <a> being to navigate to the url in the href.

    Also, whether the page opens in a new window or a new tab in the browser is solely determined by what the user has chosen in their browser settings. You can't over-ride them.

    The target element is generally deprecated now and so it shouldn't be used any longer, especially since it is no longer needed.

    2.

    Google window.open() and you should get a list of all the parameters you can use with window.open, which include parameters for sizing windows etc etc.
    Last edited by webdev1958; 03-04-2012 at 09:53 PM.


  •  

    Posting Permissions

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