SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can you open links in a new page and target a frame?

    If I have a page called index.html and another page that has frames, and the left frame, frame source is left.html. Is it possible to have all links in index.html target the frame left.html? If so, could you give me the script?

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  3. #3
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this without JavaScript. Simply give your "left.html" frame a name attribute such as "leftframe" and then add a target attribute of "leftframe" to all links in index.html:

    Code html4strict:
    <a href="#" target="leftframe">Link</a>
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, but I mean automatically have all the links on one page go to one frame on a frameset

  5. #5
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    ... Your document ...
     
    <!-- Script must got at bottom of document -->
    <script type="text/javascript">
    (function(){
        var links = document.getElementsByTagName('a'),
            length = links.length;
        while(length--) {
            links[length].target = 'leftframe'; // Change to name of left frame
        }
    })();
    </script>
     
    </body>
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Jimmy, but that didn't work
    the path is like this
    linkpage.htm <has the links, is not in the frameset
    index.html <frameset
    topframe
    leftframe <where I want the links to open
    rightframe

  7. #7
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried putting the above script in "index.html"?
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JimmyP View Post
    Have you tried putting the above script in "index.html"?
    Yes, but how do I point the <a href's > in untitled to point to index.html?

  9. #9
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sarahc33 View Post
    Yes, but how do I point the <a href's > in untitled to point to index.html?
    Sorry, what is "untitled"?
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JimmyP View Post
    Sorry, what is "untitled"?
    I am sorry not untitled, but linkpage.htm

  11. #11
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really think it's a bad idea to use JavaScript for this. If "linkpage.htm" acts as your sites navigation you don't want to rely on JavaScript to make it work properly. Additionally using frames is usally a bad idea. In fact, using frames is a bit old...

    Like I said in post #3 you need to change the target attribute of each link. Using JS is not a good solution especially when the functionality of your site depends on it.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •