SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    target=new_window

    Hi,

    To place a target=new_window in the <a> tags will open a new window. (At least in IE, haven't bothered to try in the other browsers, since this is a page I'm going to use locally)

    But how can I put the equivalent in the css?

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean target=_blank ?

    Use CSS for target attributes? I don't think target is a style property...
    Or maybe you could use javascript to assign values to the target property of all links, depending on their style class?

  3. #3
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    target=_blank would be just as well... It's just that I've used new_window before, and it worked well...

    Do you know how I could use js to assign value to classes? I haven't the slightest idea...

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I was wrong, the target property is read-only

  5. #5
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which means it's impossible?

    That's sad...

  6. #6
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing is impossible

    You can loop through all <a> tags, get the class name, the outer html (IE only, but that's no problem since it's a local file), and then change the value of outer html for each link, depending on the class name...

    Something like:
    var links = document.getElementsByTagName("a");
    for(var i = 0; i < links.length; i++)
    {
    var link = links[i];
    var cls = link.className;
    var htm = link.outerHTML;
    //... some string.replace trick here...

    }

  7. #7
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think - although I may be wrong - that if you specify a target that doesn't exist, then IE assumes that you mean a new window with that name, which would explain why new_window works for you.

    As for the target thing, it's not the way that you wanted to do it, and if you're aiming at several targets from the same page then it'll be no help at all, but have you tried including the following in the header?
    Code:
    <base target="_blank">

    Andy
    From the English nation to a US location.

  8. #8
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by jofa
    Nothing is impossible

    You can loop through all <a> tags, get the class name, the outer html (IE only, but that's no problem since it's a local file), and then change the value of outer html for each link, depending on the class name...

    Something like:
    var links = document.getElementsByTagName("a");
    for(var i = 0; i < links.length; i++)
    {
    var link = links[i];
    var cls = link.className;
    var htm = link.outerHTML;
    //... some string.replace trick here...

    }
    Hi, I'm sorry for being a little dense here, but I'll try to understand as best I can...

    First line is ok... links becomes getelementsetcetera for the <a>tag

    Second line... Hmmm... What's the "i" all about?

    I've never heard of outerHTML before... And neither am I completely sure what the string.replace is...

    Do you have the time/strength/patience to explain a little further?

  9. #9
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by awestmoreland
    I think - although I may be wrong - that if you specify a target that doesn't exist, then IE assumes that you mean a new window with that name, which would explain why new_window works for you.

    As for the target thing, it's not the way that you wanted to do it, and if you're aiming at several targets from the same page then it'll be no help at all, but have you tried including the following in the header?
    Code:
    <base target="_blank">
    Andy
    Hi,

    I haven't tried that... Should I just have that line in the header? Nothing more?

  10. #10
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by X Q mano
    I haven't tried that... Should I just have that line in the header? Nothing more?
    I think so. I've only ever tried it in the past specifying the name of a frame as opposed to _blank, but I can't see why it shouldn't work.

    It just means that all links are opened in a new window unless you specify differently on the specific link.


    Andy
    From the English nation to a US location.

  11. #11
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The i is simply the index you use when you loop through the array of <a> tags returned from getElem...

    outerHTML is like innerHTML, but outer (oh, yeah, great explanation )

    If <p>Text</p> is the tag, then innerHTML is == Text, and outerHTML is == <p>Text</p>

    Quick and dirty example:
    Code:
    <html>
      <head>
        <script type="text/javascript">
          function assignTargets() 
          { 
            var links = document.getElementsByTagName("A");
            for(var i = 0; i < links.length; i++)
            {
              var link = links[i];
              var cls = link.className;
              var htm = link.outerHTML;
              if(cls == "Cls1")
              {
                target = "_blank";
              }
              else if(cls == "Cls2")
              {
                target = "_self";
              }
              htm = htm.replace("<A", "<A target=" + target);
              link.outerHTML = htm;
            }
          }
        </script>
      </head>
      <body onload="assignTargets()">
        <a href="javascript:alert(this.target);" class="Cls1">Link 1</a>
        <a href="javascript:alert(this.target);" class="Cls2">Link 2</a>
        <a href="javascript:alert(this.target);" class="Cls1">Link 3</a>
      </body>
    </html>

  12. #12
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys!

    I tried the simplest first... It worked! So...

    Thanks to the both of you for your time, advice and patience...

  13. #13
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Recently someone in SPF responded to one of my threads saying that as "innerHTML" wasn't standards-compliant, that I should use text instead.

    Is outerHTML compliant?


    Cheers,

    Andy
    From the English nation to a US location.

  14. #14
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha, that was all you needed? I thought you wanted to add different targets to different classes... Must read more carefully

  15. #15
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, that was all I needed, sorry should have been a little more specific.

    But I'll remember this thread if I ever need different classes to the different links...

  16. #16
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by awestmoreland
    Is outerHTML compliant?
    Seems like neither of them are standard...
    http://msdn.microsoft.com/workshop/a.../innerhtml.asp
    http://msdn.microsoft.com/workshop/a.../outerhtml.asp

    However, Mozilla supports innerHTML, but not outerHTML, maybe that's why I thought that innerHTML was standard


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
  •