Web Analytics Made Easy -
StatCounter Reading href property - CodingForum

Announcement

Collapse
No announcement yet.

Reading href property

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading href property

    Hi everyone,

    I am developing my own CMS. I replaced the standard hyperlink dialog with my own, so, now my program is responsible for reading the href property. I am using IFRAME tag as an editing area and switching it to design mode by designMode property to true. I was trying to write my own code read href:

    PHP Code:
    function hyperlink()
    {
      
    editor.focus();
      if (
    editor.document.queryCommandEnabled('createlink'))
      {
        var 
    ctrl editor.document.selection.createRange();
        while ((
    ctrl.tagName != 'BODY') && (ctrl.tagName != 'A'))
        {
          
    ctrl ctrl.parentElement();
        }
        var 
    result showModalDialog("link.php"ctrl.href"resizable: no; help: no; status: no; scroll: no; dialogWidth: 328px; dialogHeight: 175px;");
        if (
    result)
        {
          
    editor.document.execCommand ('createlink'falseresult['url']);
        }
      }

    but it doesn't work. (the is written in JS of course)

    I'd appreciate any help.

    Thanks a lot!

  • #2
    If you just want to read the href property use [DOMelement].getAttribute(). I don't think this works in IE.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

    Comment


    • #3
      Originally posted by me'
      If you just want to read the href property use [DOMelement].getAttribute(). I don't think this works in IE.
      getAttribute() does work in IE.

      Comment


      • #4
        Guys, it doesn't work. ctrl.getAttribute('href'); gives an error!

        Comment


        • #5
          well one fault is that as far as I can see u can end up with ctrl being a BODY element and then u try getting this elements href which to my knowledge don't exist.

          Comment


          • #6
            How can I catch the first A tag?

            Comment


            • #7
              Originally posted by rsp12uk
              How can I catch the first A tag?
              document.getElementsByTagName('a')[0]
              David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
              W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

              Comment


              • #8
                Sorry, I wasn't very clear.

                I meant the first one in the hierarchy going up from the selection.

                Comment


                • #9
                  It should stop at the 1st A tag it meets my point was that if no A tags was encountered in that loop which is very likely considering there are just so many tags that it makes sense to put in an A tag you would end up having ctrl as a body element.

                  so perhaps put this after ur while loop

                  if(ctrl.tagName=='BODY'){alert('loop reached body rag');return;}

                  Comment

                  Working...
                  X