SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Enthusiast Jake1's Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Open a new page in JS

    Ok say I want to open a new page using JS, sizing it and setting toolbars and everything. Ok but what happens if the user has JS turned off? In that case I would like to revert to the cruder, yet still functional HTML function for doing that which is the _target="new" attribute.

    So how would I do this? I'd just like it to be so that I have a regular link, with the target atribute set to new, for when JS is turned off, but in the link also JS that will work when JS is turned on and will set the window size and settings in all.

    Thanks for any help

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a href="newpage.html" target="_blank" onmouseover="this.href='java_script_:openWinFunc()'">
    that should do it.....
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    or if you've a load of them, and you know the starting index of the first <a> (document.getElementsByTagName('a').length at beginning)
    then you could do the lot onload, just leave your links in HTML then onload or with the js after HTML you could use this...
    Code:
    for(i=20;i<30;i++) {
    link=document.getElementsByTagName('a')[i]
    link.href="java_script_:window.open(link.href,link.href.split('.')[0],'width=150,height=150,toolbar=no,location=no')";
    }
    the 20 to 30 will need to be changed for your <a> references
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll probably want to use the onclick event handler. The "return false" statement prevents the browser from opening a blank window.

    Code:
    <script type="text/javascript">
    
    function openWindow (url){
    	// Put your window opening script here
    }
    
    </script>
    
    <a href="somepage.html" target="_blank" onclick="openWindow(this.href); return false;">Some Link</a>
    travis

  5. #5
    SitePoint Zealot johno's Avatar
    Join Date
    Sep 2003
    Location
    Bratislava, Slovakia
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Annotations support for PHP5
    TC/OPT™ Group Leader

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    johno. just curious, why wouldn't you just return false out the event handler?
    travis

  7. #7
    SitePoint Zealot johno's Avatar
    Join Date
    Sep 2003
    Location
    Bratislava, Slovakia
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because when you call window.open() and the window will not be opened (blocked by user settings in browser) the link will not be functioning. So i'm checking if the window was realy opened by if(!newWindow) ...
    Annotations support for PHP5
    TC/OPT™ Group Leader

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gotcha. nicely done.
    travis

  9. #9
    SitePoint Enthusiast Jake1's Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yay, thanks guys, those worked great!


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
  •