0

I have an issue with using <object>. I need it to show different external pages, but it's not really working for me. It is like, after the first time I set Data, changing it does nothing. Do I need to refresh it, somehow?

This is my jQuery code to change the data:

$("#content").attr('data', urls[urlIdx]);

And my object:

<div id="Main" style="width:100%;height:100%;">
    <object id="content" style="width:100%;height:100%;"/>
</div>

Simple stuff.

urls is an array of urls, and urlIdx is a counter that I increment.

Edit: I have made this jsfiddle: http://jsfiddle.net/fJQm6/

Basically, the first time the tick executes, the object's data is set, but the subsequent ticks changes nothing.


First off, object is for embedded things like video etc. see here

What you might want to use instead is a iframe here

<iframe id="test" src="http://www.w3schools.com"></iframe>

You could then use jquery to set attr.

$('#test').attr('src','http://www.google.co.uk');

Update

Object can be used for webpages but iframe is preferred.

fiddle updated with iframe.

4

2 回答 2

0

Possible duplicate of Changing data content on an Object Tag in HTML

var divEl = document.getElementById('Main');
var objEl = document.getElementById('content');
objEl.data = newUrl; //you can use aray logic here
// Refresh the content
divEl.innerHTML = divEl.innerHTML;

using Jquery

$("#content").attr('data', urls[urlIdx]);
var $mainDiv=$("#Main");
$mainDiv.html($mainDiv.html());

Here is updated live jsfiddle http://jsfiddle.net/fJQm6/3/

于 2013-04-24T11:26:58.150 回答
0

首先,object用于视频等嵌入式内容,请参见此处

您可能想要使用的是iframe 这里

<iframe id="test" src="http://www.w3schools.com"></iframe>

然后,您可以使用 jquery 来设置 attr。

$('#test').attr('src','http://www.google.co.uk');

更新

Object可用于网页,但iframe首选。

fiddle用 iframe 更新。

于 2013-04-24T11:04:45.363 回答