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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Window focusing

  • 04-08-2005 10:37am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,170 ✭✭✭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, Registered Users 2 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, Registered Users 2 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: 41,228 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, Registered Users 2 Posts: 21,263 ✭✭✭✭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, Registered Users 2 Posts: 2,170 ✭✭✭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: 41,228 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, Registered Users 2 Posts: 21,263 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 21,263 ✭✭✭✭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, Registered Users 2 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