该嵌入 HTML 的对象不会在 IE 中呈现

发布于 2024-11-09 03:38:51 字数 1553 浏览 4 评论 0原文

首先,我要声明我的网络编程技能非常有限。

我希望我能得到一些帮助来尝试让这个目标代码正常工作。

我经营一家 eBay 商店,有多个商品列表。我想出了一个想法,如果我可以为左侧(针对不同的产品)创建一个导航菜单作为独立的 html 文件,并以某种方式获取该数据并将其包含在每个列表中,这意味着我可以简单地更新该文件和我的所有列表都将有一个更新的导航菜单。

该代码似乎在除 IE 之外的所有浏览器中都能正常运行。这是我使用的代码:

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

我真的不确定我需要做什么才能让它在 IE 中正常工作。说实话,我真的不太明白这一点。

请温柔一点,因为我非常渴望学习。在开始自己的生意之前,我几乎没有任何网页设计技能,我觉得仅仅通过从这样的网站学习我就已经取得了很大的进步。

非常感谢您提前。

编辑:我决定测试没有“text/javascript”部分的页面。我只是将对象元素留在了 DIV 中。我只留下这段代码:

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

这在除 IE 之外的所有浏览器上都能完美运行。我显然不知道我需要使用哪个代码。我认为需要“text/javascript”部分才能从外部页面调用 HTML 代码。

编辑2:我发现一些信息表明IE可以支持嵌入HTML的对象元素,但需要“classid”标签。我还用以下内容包装了两个不同的版本:

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

但是,这仍然不起作用。

我还尝试使用相同的代码(不同的源 HTML 文件除外)拉入菜单的另一部分(顶部/水平)。

此代码在除 IE 之外的所有浏览器中也可以完美运行。奇怪的是 IE 试图将应该位于左侧的菜单放入顶部部分,即使没有代码表明它应该这样做......?

在嵌入的 html 中包含样式信息而不是单独的样式表会导致 IE 出现问题吗?这不会对所有其他浏览器造成问题。当然,我计划在它正常工作后将其分开。

为了澄清我的要求,假设我有 100 个 eBay 列表,每个列表都有一个自定义的左侧导航菜单。如果我更改该导航菜单,我将需要进入每个列表并手动编辑代码(复制和粘贴)以更新菜单。因此,我想保留一个仅包含菜单的外部 HTML 文件,然后使用对象标记或类似的内容将该信息动态拉入每个列表中。

请注意,eBay 不允许 iFrame,所以我真的需要一个替代方案。有什么建议吗?

我很乐意付钱给网络开发人员来解决这个问题或为我指出正确的方向,但我不确定关于这种类型的脚本该联系谁。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱你不解释 2024-11-16 03:38:51

首先,您是否收到错误消息?查看此内容以及消息指向的代码行总是有用的,您甚至可以自己解决问题。

其次,您不能(或者更确切地说:不应该)将字符串分成多行。正如您所看到的,语法突出显示变得混乱,IE 的 JavaScript 引擎也是如此。如果您想将长字符串文字分布在多行上,请关闭并连接每个部分,例如:

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

第三,您不应该更改 documentinnerHTML,但是您要更改的元素的名称。使用 document.getElementById 来实现:

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

第四,我认为你的方法是完全错误的:不要使用 JavaScript 动态添加菜单,而是使用 PHP 等服务器端脚本来动态插入导航菜单和之类的。如果 JavaScript 不可用(例如,对于多个搜索引擎和视力障碍者),用户或机器人将看不到您的菜单,这当然是一个可怕的缺点。

第五,我认为在继续之前你真的应该读一本关于 JavaScript 的好书。只是我的 0.02 欧元。

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.

夏尔 2024-11-16 03:38:51

您似乎正在尝试更新文档对象本身的内部 HTML - 该对象保存整个页面,包括 eBay 信息。

此外,document 对象实际上从未显示 - document 应该有一个 body 属性,其中包含页面的实际可见 HTML,您应该更新它(可能不仅仅是用您的文本替换它,而是以某种方式添加到它)。

通常,人们会在 HTML 中找到想要将菜单放入其中的部分 - 例如,假设您的所有项目的描述中都有此 HTML:

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

然后您可以通过找到 DIV 来添加一些 HTML元素并替换为其内部 HTML(而不是整个文档的 HTML):

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

我不太明白问题的最后几段,但这不是“ActiveX”,Internet Explorer 可能会抱怨您试图覆盖文档的全部内容。 “ActiveX”是一种技术,允许人们用 C 编写程序,当您尝试访问某些网站时,这些程序在浏览器内运行,但由于不安全和其他问题,目前尚未使用。

编辑: Laslty,您真正的问题可能是 IE 不允许在 HTML 内容中嵌入对象。使用 IFRAME 标记而不是 OBJECT 标记来托管外部 HTML 内容(带或不带 javascript 初始化)可能是更好的主意。只需确保设置 iframe 对象的宽度和高度,因为 iframe 不会自动扩展以适应内容,并且默认大小可能不适合您。

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.

德意的啸 2024-11-16 03:38:51

问题是 IE 对对象标记中的数据发出 HEAD 请求,但您的服务器设置为仅接受 GET 请求。

约翰

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文