SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2001
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript for new window, but don't want page to move back to the top. ????

    I have the following code in my page:


    <a href="#" onclick="window.open('file.htm' ,'HTML_file','toolbar,scrollbars,height=160,width=350')">link</a>

    when you click the link the little pops up like its supposed to, but the page moves back to the top, is there a way to stop this?

    thanks,

    michael.
    __________________________
    http://www.michaelsica.com

  2. #2
    How Much Money?
    Join Date
    Aug 2001
    Location
    Liverpool, UK
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have been having trouble with this but i gave up after a while as it doesent make that much difference.

    although it is annoying having a a script do something that you dont want it to.

    you only way to get around this is to pay for someone to fix it.

    Matthew Taylor
    AutomatedLinks.com
    Boost your search engine ranking, by increasing your link Popularity,
    Dynamically.

  3. #3
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No need to pay anyone for this. What's happening is the link you are setting up points back to the top of the page because there is no anchor on the page named "#". So, give your anchor a name, so that the href property essentially points back to itself:
    Code:
    <a href="#foo" name="foo" onclick="window.open('file.htm' ,'HTML_file','toolbar,scrollbars,height=160,width=350')">link</a>
    Rob Nolan
    Do or do not, there is no try.

  4. #4
    SitePoint Member Variable's Avatar
    Join Date
    Nov 2001
    Location
    Mississippi, USA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, IE 5.0+ (and possibly other browsers) support using JavaScript in the actual HREF of the link. For example:

    Code:
    <A HREF="javascript: window.open('new.html','New_Page','height=350,width=250,toolbar=no,resizable=yes,scrollbars=no'); return true">
    I'm not sure which browsers support it, so if compatibility is an issue, you might want to go with RogueJedi's answer.
    i - p o r t f o l i o |-[ X/pression [LTN] | B & B H | Renegade Online ]
    c o n t a c t i n g |-[ cyph0r@bellsouth.net | Variable K Cubed | PM ]

  5. #5
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: JavaScript for new window, but don't want page to move back to the top. ????

    <a href="#" onclick="window.open('file.htm' ,'HTML_file','toolbar,scrollbars,height=160,width=350')">link</a>


    [/B]
    You are using the # in your href. It is searching for a named tag to move to when it doesn't find one it moves to the top. In some text near where you want the screen to stay place

    this places a marker in that area
    <a name="bob"></a>

    Then just change your <a> to
    <a href="#bob" onclick="window.open('file.htm' ,'HTML_file','toolbar,scrollbars,height=160,width=350')">link</a>

    Should work.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  6. #6
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Variable
    Also, IE 5.0+ (and possibly other browsers) support using JavaScript in the actual HREF of the link. For example:

    Code:
    <A HREF="javascript: window.open('new.html','New_Page','height=350,width=250,toolbar=no,resizable=yes,scrollbars=no'); return true">
    I'm not sure which browsers support it, so if compatibility is an issue, you might want to go with RogueJedi's answer.
    Except that is considered incredibly bad form and a misuse of the href attrib. It can be done but proper form dictates a

    <a href=javascript:void(0) onclick="event code"></a>
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  7. #7
    SitePoint Member Variable's Avatar
    Join Date
    Nov 2001
    Location
    Mississippi, USA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I never was too familiar with standards

    I was simply taking a page from the IE error page.
    i - p o r t f o l i o |-[ X/pression [LTN] | B & B H | Renegade Online ]
    c o n t a c t i n g |-[ cyph0r@bellsouth.net | Variable K Cubed | PM ]

  8. #8
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Variable
    I never was too familiar with standards

    I was simply taking a page from the IE error page.
    no biggy. I even made an error in my code. haha.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  9. #9
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erm, wait a minute. Which is considered bad form? My example or the <A HREF="java script: window.open('new.html'...')</a> thing?

    If I'm writing bad code, I'd sure like to know about it.
    Rob Nolan
    Do or do not, there is no try.

  10. #10
    SitePoint Member Variable's Avatar
    Join Date
    Nov 2001
    Location
    Mississippi, USA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My example, using the JavaScript as the target of the HREF is bad form. Which makes sense, I wouldn't expect IE-embedded HTML to be cross-browser compliant...
    i - p o r t f o l i o |-[ X/pression [LTN] | B & B H | Renegade Online ]
    c o n t a c t i n g |-[ cyph0r@bellsouth.net | Variable K Cubed | PM ]

  11. #11
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, OK.

    I didn't realize using a javascript as the target for an href was bad form, tho'. I'll keep that in mind for future projects.
    Rob Nolan
    Do or do not, there is no try.


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
  •