SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy question for you guys

    I'm opening a new window in JavaScript. How do I do so via a standard textual link? -- 'onclick=""' does not seem to do the trick. It only seems to work with buttons.

    Thanks.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  2. #2
    Bimbo With A Brain! silver trophy Saz's Avatar
    Join Date
    Mar 2001
    Location
    Kent, United Kingdom
    Posts
    5,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For a standard text link you would have:
    Code:
    <a href="your_page.html">text link</a>
    right?

    Well try this instead:
    Code:
    <a href="javascript:openWindow('your_page.html')">text link</a>
    Obviously, the "openWindow" bit will have to be changed to whatever function name you have for your script.

    This is the method I use, so I know it works. :)
    Saz: Naturally Blonde, Naturally Dizzy!
    No longer Editor of the Community Crier.

    Don't mind me, I'm having a BLONDE moment!

  3. #3
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Saz. That'll do the trick.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <a href="#" onClick="window.open('http://members.aol.com/grassblad','','width=300,height=300')">GrassBlade</a>

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another slight problem. Here's the code I'm now using:
    Code:
    <a href="javascript:window.open('directives.php#dproject','Directives',
    'width=500,height=300,scrollbars=yes,resizable=no')">District Project</a>
    However, in Internet Explorer 6.x at least, the window takes several seconds to appear and the main page reloads with the text "[object]" in it.

    Why is the main page reloading and the new window taking so long to initiate?

    EDIT: Hold on; let me see if Vinny's does the trick.
    Last edited by Aes; Dec 28, 2001 at 12:29.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  6. #6
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinny, using your model doesn't reload the initial page to "[object]," which is great. However, the anchor tag (#whatever) isn't passed to the new window either.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  7. #7
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The # is intended as a place holder, but you should use jav&#097;script:void(0) instead.
    ck :: bringing chris to the masses.

  8. #8
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The "javascript:void(0)" works well. Thanks. But the anchor link still isn't being passed to the new window. Do you know why this is?
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  9. #9
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi AES,

    'directives.php#dproject'
    Is the '#dproject' supposed to bring you to an anchor named 'dproject'? If so, it should work -- in html. But, you are opening a php page, so the question is: what are you doing on the php side to read the attached?
    I ask because:
    1) php is not my forte, so I have no idea whether it is handling it the same as javascript/html
    2) when passing arguments (in javascript), the convention is: somepage.xxx?arguments (with the arguments being parsed using location.search.substr(1) ) Perhaps you need to do the same -- or move this thread to the php forum.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  10. #10
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code i use for a popup, nice and easy

    <A HREF="#" onClick="window.open('http://www.whatever.com',
    'newWnd', 'width=370,height=220,toolbar=1,menubar,location,status=1,scrollbars=1,resizable=1');return
    false;">Here</A>
    i didnt read every reply so excuse me if its already there

  11. #11
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a purely HTML issue, as Javascript just opens the correct page in a new window, and it will certainly include any anchor link that you give it. The only reason that the anchor would not work is if the <a name="blah"></a> doesn't exist. Post some urls and I can verify the code.
    ck :: bringing chris to the masses.


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
  •