www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: [RESOLVED] Accessing Hidden Object Content

  1. #1
    Join Date
    Aug 2010
    Posts
    51

    resolved [RESOLVED] Accessing Hidden Object Content

    I've got a hidden object in my head element and I want to access the content of the element when I change the source. I'm doing it like this because putting it directly in the page does not allow for dynamic height and so I want the browser to simply copy the content into a specific element. I already know how to access the element but I don't know how to access the content on all the main desktop browsers.

    Could someone post the available methods, I can research the rest once I've got that.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Give a code example of the problem
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Aug 2010
    Posts
    51

    Post

    HTML
    Code:
    <head>
        <script src=site.js type=text/javascript></script>
        <object id=obj classid=classid:? type=text/html data=about_data.php>
                object is added via javascript, classid is used only when in ie
        </object>
    </head>
    <body>
        <div id=nav>bunch of anchors that use the onclick event to cancel the link and load object</div>
        <div id=content>where content of obj is copied to</div>
    </body>
    JavaScript
    Code:
    var get = {};
    function site () { // used at window.load
        site.get = function () {}; // load location.search into global get
        site.get.id = document.getElementById;
        // I actually use typeof to detect this or document.all else create a function that returns null always
    }
    site.ajax = function () {
         var r = "";
        // attempt xhr
        // if fail use obj
        // if still fail use iframe
        // if still fail do nothing with r else r grabs content of xhr / obj / iframe as string
        return r;
    };
    site.nav = function () {
        var a = arguments[0];
        x = site.ajax(a.href);
        if (x !== "") {
            e = site.get.id("content");
            if (e !== null) {
                e.innerHTML = x;
                return false;
            }
        } return true;
    };
    This is highly simplified skipping a great deal of code. The point of the site.nav is to use ajax if it can otherwise let php handle it. The point in using anchors is to allow the site to be used even if there is no javascript (applied this rule to css as well).
    The current location where I upload is wdaisy.cz.cc (not updated yet). This is for a friend so don't go assuming I got weird tastes for a guy.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Why have an object in the head?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Aug 2010
    Posts
    51

    Post

    Because the object height can't be made to adapt to it's content via css which prevents making the content of the object seem like part of the page itself rather than inside an object box. And since the head and it's elements are supposed to be hidden that becomes the best place for the object in the event that css is disabled.

    Edit: it's only with html, json & plain text that I do this, all other embeded content is done normally.
    Last edited by awsdert; 08-26-2010 at 02:12 AM.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Hiding the object with property display or z-index does not work?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Aug 2010
    Posts
    51

    Post

    of course it works but my way of designing is to use css as an enhancement not a neccessity and by simply using css to hide it will allow it to appear when css is disabled thereby defeating the purpose of using css as an enhancement. This is why I must take advantage of the head elements default properties to prevent the site looking bad when css is disabled. now back to the reason I made this thread, what are the properties/functions available to access the content of the object. I tried doing a search on this but it kept returning so much junk that it made finding useful information impossible.

  8. #8
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    document.getElementsByTagName('object')[0].foo
    At least 98% of internet users' DNA is identical to that of chimpanzees

  9. #9
    Join Date
    Aug 2010
    Posts
    51

    Post

    foo? I don't even know the property or method there, as for the get id thing i already knew that, you're not answering my question at all. How do I access the file called by the data parameter?

  10. #10
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    document.getElementById('obj ').contentDocument.body.innerHTML
    At least 98% of internet users' DNA is identical to that of chimpanzees

  11. #11
    Join Date
    Aug 2010
    Posts
    51
    That does not return the content of the file referred to by the DATA attribute. Please only reply if you know what your talking about and not the current page's dom which I did not ask for.

  12. #12
    Join Date
    Aug 2010
    Posts
    51

    Post

    Oops, didn't notice that contentDocument bit, my bad, I'll try it out.

  13. #13
    Join Date
    Aug 2010
    Posts
    51
    My browser told me that contentDocument does not exist, are you sure this is the method?

  14. #14
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    contentDocument works for conforming browsers. The equivalent for IE is contentWindow.document
    Unfortunately IE does not support this in <object>. Using an iframe is simpler and better supported.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  15. #15
    Join Date
    Aug 2010
    Posts
    51

    Post

    I'm doing all my tests in Firefox 4b4 & IE8 in quirks mode, I'm pretty sure Firefox is compliant and IE8 was a result of installing windows 7 otherwise I'd be using IE6

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles