skip to Main Content

First, I will declare that my web programming skills are VERY limited.

I am hoping I can receive some help in trying to get this object code to work correctly.

I run an eBay store with multiple listings. I came up with the idea that if I could create a navigation menu for the left hand side (for different products) as a stand alone html file and somehow fetch that data and include it in each listing that it would mean that I could simply update that one file and all my listings will have an updated navigation menu.

The code seems to work well in every browser except IE. This is the code I used:

<div id="object">
<object id="Menu" name="Menu" type="text/html" data="http://www.website.com.au/menu.html"></object>
</div>

I am really not sure what I need to do to get this to work correctly in IE. To be completely honest, I don’t really don’t understand this much at all.

Please be gentle as I am very keen to learn. Prior to commencing my own business I had virtually no web design skills at all and I feel I have come long way just by learning from sites likes this.

Thank you so very much in advance.

EDIT: I decided to test the page without the “text/javascript” section. I simply left the object element within the DIV. I only left this code in:

<object id=Menu name=Menu type="text/html" data="http://www.website.com./menu.html"></object>

This works perfectly on all browsers except IE. I obviously have no idea which code I need to use. I thought that the “text/javascript” section was required to call the HTML code from an external page.

EDIT 2: I came across some information suggesting that IE can support object elements with HTML embedded but require the “classid” tag. I also wrapped the two different versions with:

"<!--[if IE]>"... <!--[if !IE]> <!-->... etc.

However, this still does not work.

I also just tried to pull in another section of menu (top/horizontal) with the same code (except different source HTML file).

This code also works perfectly in all browsers except IE. The odd thing is IE is trying to put the menu that should be on the left hand side into the top section, even though no code suggests that it should do this…?

Would having style information inside the embeded html instead of a separate style sheet cause issues for IE? This doesn’t cause issues for all other browsers. Of course I plan to separate it once I get it working correctly.

To clarify my requirement, say I have 100 eBay listings each with a customised left navigation menu. If I change that navigation menu, I would need to go into every single listing and edit the code manually (copy and paste) to update the menu. So I want to keep an external HTML file that consists of the menu only and then use an object tag or something similar to pull that information into each listing on the fly.

Please note that eBay does not allow iFrames so I really need an alternative. Any suggestions?

I would be happy to pay a web developer to fix this or point me in the right direction but I am not sure who to contact in regards to this type of script.

3

Answers


  1. You seem to be trying to update the inner HTML of the document object itself – the object that holds the entire page, including the eBay information.

    Also, the document object is not actually ever displayed – document should have a body property that contains the actual visible HTML of the page and you should update that (and probably not just replace it with your text but add to it somehow instead).

    Normally what people do, is they find the section in their HTML that they want to put the menu inside – for example, suppose you have this HTML in all of your items’ descriptions:

    <div id="menu_object"></div>
    

    You can then add some HTML into it by locating the DIV element and replacing to its inner HTML (instead of the HTML of the entire document):

    function addMenu(which) {
        var myDiv = document.getElementById("menu_object");
        myDiv.innerHTML = '<'+'object id="Menu" name="Menu" type="text/html" data="'+which.href+'"></object>';
    }
    

    I don’t really understand the last few paragraphs of the question, but this is not “ActiveX”, and Internet Explorer probably complained that you were trying to overwrite the entire content of the document. “ActiveX” is a technology that allows people to write programs in C that run inside the browser when you try to access some websites, and is not used today because it is not secure and due to other concerns.

    Edit: Laslty, your real problem might be that IE does not allow embedding objects with HTML content. Its probably a better idea to use an IFRAME tag instead of an OBJECT tag to host your external HTML content (with or without the javascript initialization). Just make sure to set the width and height of the iframe object because iframes do not automatically expand to fit the content and the default size likely will not work for you.

    Login or Signup to reply.
  2. First of all, do you get an error message? It’s always useful to look at this and the line of code the message points to, you might even be able to solve the problem yourself.

    Second, you can’t (or rather: shouldn’t) divide strings over multiple lines. As you can see, the syntax highlighting gets confused and so will be IE’s JavaScript engine. If you want to spread a long string literal over multiple lines, close and concatenate each part, like:

    element.innerHTML = '<object id="Menu" name="Menu" type="text/html"' +
                        'data="'+which.href+'"></object>';
    

    Third, you shouldn’t change the document‘s innerHTML, but that of the element you want to change. Use document.getElementById for that:

    document.getElementById("object").innerHTML = '…';
    

    Fourth, I think your approach is totally wrong: don’t add menus on-the-fly using JavaScript, use server-side scripting like PHP to dynamically insert navigation menus and the like. If JavaScript is unavailable (e.g., to several search engines and the visually impaired), a user or bot won’t see your menu, which is of course a horrible drawback.

    Fifth, I think you really should read a good book on JavaScript before going on. Just my € 0.02.

    Login or Signup to reply.
  3. The problem is that IE issues a HEAD request for the data in the object tag, but your server is setup to only accept GET requests.

    John

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search