Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Window focusing

Options
  • 04-08-2005 11:37am
    #1
    Registered Users Posts: 3,012 ✭✭✭


    hey,

    is it possible to get the browser to focus on a window that has no html in it?

    I have a page with a load of PDF's on it, all of which open in a new window.

    Is there anyway to declare it on the page so that once the PDF is loaded in the other window, to focus on it?


Comments

  • Registered Users Posts: 2,157 ✭✭✭Serbian


    Hrm, try creating your links like this:
    <a href="document.pdf" target="_blank" onClick="child.focus();">I'm a PDF document!</a>
    

    I was under the impression that all pages that open in a new window automatically focus though.


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    Yes, but if you open another PDF from the same parent, the 2nd one doesn't focus.

    Cheers dude, I'll try that child.focus() now.


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    didn't work, as long as the new window is open, any other document loaded into it doesn't get focused on..


  • Moderators, Politics Moderators Posts: 39,933 Mod ✭✭✭✭Seth Brundle


    You could get javascript to open a new window (onclick instead of using href in the <a> tag) with a name and then use the window name as the target.
    Im off to lunch now so I won't type it all out.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    BizzyC wrote:
    didn't work, as long as the new window is open, any other document loaded into it doesn't get focused on..

    Are you effectively reloading the child window each time you click a link on the parent window? If so, in the child window:
    <body onload="window.focus()">
    
    may work


  • Advertisement
  • Registered Users Posts: 2,157 ✭✭✭Serbian


    eoin_s wrote:
    Are you effectively reloading the child window each time you click a link on the parent window? If so, in the child window:
    <body onload="window.focus()">
    
    may work

    He's specifically looking to focus a window that doesn't conatin HTML (they will contain a PDF document instead).


  • Moderators, Politics Moderators Posts: 39,933 Mod ✭✭✭✭Seth Brundle


    Just thinking about it, my suggestion wouldn't work either as theres no HTML in it.
    However, you could possibly use a frame to contain the pdf


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Serbian wrote:
    He's specifically looking to focus a window that doesn't conatin HTML (they will contain a PDF document instead).

    Oops, sorry. Wasn't thinking right :o

    how about:
    <script type="text/JavaScript">
    	function openPDF(sFileName)
    	{
    		var myWin = window.open(sFileName,"PDF_DOC", "your window attributes here")
    		myWin.focus();
    	}
    </script>
    
    <a href="JavaScript: openPDF('myFile.pdf');">My PDF</a>
    

    Updated:

    Just tested that by clicking on the first link, which opened the PDF in a new window as expected. Didn't close that new window, went back to the parent window and clicked on the 2nd link. That loaded the 2nd PDF into the same child window, and set the focus to the child window.

    Is that what you wanted OP?

    Eoin


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    Yeah that's what I was looking for Eoin.

    But is there any chance of that being blocked like a pop-up?


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    BizzyC wrote:
    Yeah that's what I was looking for Eoin.

    But is there any chance of that being blocked like a pop-up?

    That is always a risk - some popup blockers will block any, where as some (like the google toolbar) only seem to block ones that are called when the window loads, as opposed to when it is specifically called from a link.

    Out of curiosity, I just created a page that links to 2 PDF docs using normal HTML and specified a target with a specific name (myPage):
    	<a href="myFile1.pdf" target="myPage">My PDF1</a> |
    	<a href="myFile2.pdf" target="myPage">My PDF2</a>
    

    Again, I clicked on the first link and left the new window open. I went back to the first page, and clicked on the second link, and the new window got the focus - so maybe you don't need JavaScript at all?

    Eoin


  • Advertisement
  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    eoin_s wrote:
    That is always a risk - some popup blockers will block any, where as some (like the google toolbar) only seem to block ones that are called when the window loads, as opposed to when it is specifically called from a link.

    Out of curiosity, I just created a page that links to 2 PDF docs using normal HTML and specified a target with a specific name (myPage):
    	<a href="myFile1.pdf" target="myPage">My PDF1</a> |
    	<a href="myFile2.pdf" target="myPage">My PDF2</a>
    

    Again, I clicked on the first link and left the new window open. I went back to the first page, and clicked on the second link, and the new window got the focus - so maybe you don't need JavaScript at all?

    Eoin

    No, I've done the same already, but there's no focusing the second time around, unless the original page is reloaded.

    Actaully, it works for every 2nd pdf you open....weird.


Advertisement