+ Post New Thread
Results 1 to 10 of 10
Web Development Thread, php script help - open in a new window in Coding and Web Development; hi there, using this PHP script how can i make it so documents open in a new windows please? thanks...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    php script help - open in a new window

    hi there,

    using this PHP script how can i make it so documents open in a new windows please?

    thanks
    Attached Files Attached Files

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,413
    Thank Post
    642
    Thanked 964 Times in 664 Posts
    Blog Entries
    2
    Rep Power
    327
    Line 116

    Find

    Code:
    <a href="'+f['url']+'">
    Change to

    Code:
    <a href="'+f['url']+'" target="_blank">
    Should work.

  3. #3
    penfold_99's Avatar
    Join Date
    Feb 2008
    Location
    East Sussex
    Posts
    985
    Thank Post
    58
    Thanked 165 Times in 117 Posts
    Rep Power
    68
    when you generate the html link are you including

    target="_blank"

    in the a href tag?

  4. #4

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by penfold_99 View Post
    when you generate the html link are you including

    target="_blank"

    in the a href tag?
    Isn't that what webman just said?

  5. #5

    Join Date
    Sep 2008
    Location
    Edinburgh
    Posts
    12
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I don't know if you care much about web standards and accessibility but the target attribute was deprecated in HTML 4.01.

  6. #6

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461
    Quote Originally Posted by webman View Post
    Line 116

    Find

    Code:
    <a href="'+f['url']+'">
    Change to

    Code:
    <a href="'+f['url']+'" target="_blank">
    Should work.
    Thanks but, that didnt work when i was opening a word document.

    Z
    Last edited by FN-GM; 12th September 2008 at 10:20 AM.

  7. #7
    Friez's Avatar
    Join Date
    Dec 2006
    Posts
    839
    Thank Post
    22
    Thanked 22 Times in 21 Posts
    Rep Power
    23
    This is because your browser seems to have an embedded thing for word docs (eww).

    IF what you're asking for is for a download prompt for the word document rather than have it appear in-browser, attempt the PHP below (passing in the path to the file and filename) and see what happens with that.

    The header is what defines if the file downloads or if it shows up embedded in the browser, setting this up right (my script may need tweaking as necessary) will force a download rather than display it in-browser.

    If you REALLY want the word document to show up in another window, you will need to ensure the link to it include target="_blank" as others have mentioned. I see no reason why this wouldn't work as the launch target is always triggered before the url in the href parameter is passed.

    Here's my PHP Code for manually dishing up files. Be sure that this code is the ONLY thing that runs on a page (i.e. make a download.php and hook in the file to download e.g.: Download("c:\mydoc.txt","mydoc.txt");

    Any whitespace that is additionally exported (or indeed any html) will corrupt the file.

    PHP Code:
    function urlcode($stringname) {
        return 
    str_replace(" ","%20",str_replace("'","%27",$stringname));
    }

    function 
    Download($f_location,$f_name)
    {
        
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        
    header('Content-Description: File Transfer');
        
    header('Content-Type: application/octet-stream');
        
    header('Content-Length: ' filesize($f_location));
      
        
    // MSIE doesn't play ball, it requires spaces to be %20  
        
    if (eregi("MSIE",$_SERVER['HTTP_USER_AGENT'])) 
        {
            
    header('Content-Disposition: attachment; filename="' urlcode(basename($f_name)) . '"');    
             
        }   
        else
        {
            
    header('Content-Disposition: attachment; filename="' basename($f_name) . '"');
        }
        
    readfile($f_location); 
     } 

  8. #8
    Friez's Avatar
    Join Date
    Dec 2006
    Posts
    839
    Thank Post
    22
    Thanked 22 Times in 21 Posts
    Rep Power
    23
    Quote Originally Posted by theboyhope View Post
    I don't know if you care much about web standards and accessibility but the target attribute was deprecated in HTML 4.01.
    What was it replaced with in HTML 4.01? I mean, the draft for HTML 5 appears to only have shown up today on the w3c.... So really pretty much most web browsers are gonna handle HTML 4.01 in the real world, and it is rare to fully remove deprecated functionality within two or three major versions.
    Last edited by Friez; 12th September 2008 at 11:35 AM.

  9. #9

    Join Date
    Sep 2008
    Location
    Edinburgh
    Posts
    12
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    The browser will handle it, certainly. He's running with a strict doctype though.

    Just letting him know that he can't use the target attribute and XHTML 1.0 Strict if the page has to validate.

    In my opinion, there never has been an acceptable replacement for it really and I think it's back in the XHTML 1.1 core spec. I find it's easiest to fall back to the Transitional doctype if the project has to pass validation.

  10. #10
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    896
    Thank Post
    84
    Thanked 235 Times in 194 Posts
    Rep Power
    82
    What was it replaced with in HTML 4.01?
    It wasn't. Javascript became the solution (and still is for a lot of folks)

    eg:

    newwindowlink.js

    Code:
    function initLinks() {
      for (i in document.links) {
        link = document.links[i];
        if (link.rel && link.rel.indexOf('external')!=-1) {
          link.onclick = onExternalLinkActivate;
          link.onkeypress = onExternalLinkActivate;
        }
      }
    }
    
    function onExternalLinkActivate() {
      window.open(this.href);
      return false;
    }
    
    window.onload = initLinks;

    Declare in page HEAD with:
    Code:
    <script src="newwindowlink.js" type="text/javascript"></script>
    Then link becomes:
    Code:
    <a href="http://site.com" rel="external">some site</a>

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 4
    Last Post: 18th November 2011, 03:36 PM
  2. [CLOSED] Improvement: Open in new window
    By Lee_K_81 in forum EduGeek.net Site Problems
    Replies: 10
    Last Post: 8th January 2008, 08:25 AM
  3. Blogs top open in new window or new tab
    By ITWombat in forum Comments and Suggestions
    Replies: 3
    Last Post: 22nd July 2007, 01:35 PM
  4. Open each folder in the same window
    By mark in forum Windows
    Replies: 2
    Last Post: 30th May 2007, 01:09 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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