Connecting Tech Pros Worldwide Help | Site Map

Add OBJECT in DIV

Asterbing
Guest
 
Posts: n/a
#1: Nov 30 '05
Hi. I'm trying to add an OBJECT in an existing DIV after a certain
delay.

Here is my currend code :

<div id="dummy" style="position: absolute; visibility: visible; top:
10px; left: 10px; z-index: 5; cursor: default; height: auto; background:
white; width: 500px; padding: 5px; overflow: hidden;>
<script language="JavaScript"><!--
var code = document.createTextNode("<object width='400'
height='400' type='text/html' data='soon.htm'></object>");

var obj = findObject("dummy"); // findObject existing in a .js

setTimeout(function(){obj.appendChild(code);},6000 0);
//--></script>
</div>

The result is that after 60 seconds, the DIV contains the text
"("<object width='400' height='400' type='text/html' data='soon.htm'>
</object>" and not an interpreted object tag. How to add the object
rather than simple text ?
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Nov 30 '05

re: Add OBJECT in DIV


Asterbing wrote:

| From: Asterbing <no@thanks.com>

As you wish.


PointedEars
Asterbing
Guest
 
Posts: n/a
#3: Nov 30 '05

re: Add OBJECT in DIV


In article <MPG.1df82f045394a68798971a@news.tiscali.fr>, no@thanks.com
says...[color=blue]
> Hi. I'm trying to add an OBJECT in an existing DIV after a certain
> delay.
>
>[/color]

OK, done... Uless that the html file which has to be loaded in the
created <object> tag is well loded under Netscape 7 but not under IE6
nor Opera : the object remains empty (without soon.htm rendered).

Here is the new code :

<div id="dummy" style="position: absolute; visibility: visible; top:
10px; left: 10px; z-index: 5; height: auto; width: 300px; padding: 5px;
overflow: hidden;>
<script language="JavaScript"><!--
setTimeout(function()
{
var obj,elt;

elt = document.createElement("object");
elt.setAttribute("width","280");
elt.setAttribute("height","500");
elt.setAttribute("type","text/html");
elt.setAttribute("data","soon.htm");

obj = findObj("dummy");
obj.appendChild(elt);
},10000);
//--></script>
</div>
RobG
Guest
 
Posts: n/a
#4: Nov 30 '05

re: Add OBJECT in DIV


Asterbing wrote:[color=blue]
> In article <MPG.1df82f045394a68798971a@news.tiscali.fr>, no@thanks.com
> says...
>[color=green]
>>Hi. I'm trying to add an OBJECT in an existing DIV after a certain
>>delay.
>>
>>[/color]
>
>
> OK, done... Uless that the html file which has to be loaded in the
> created <object> tag is well loded under Netscape 7 but not under IE6
> nor Opera : the object remains empty (without soon.htm rendered).
>
> Here is the new code :
>
> <div id="dummy" style="position: absolute; visibility: visible; top:
> 10px; left: 10px; z-index: 5; height: auto; width: 300px; padding: 5px;
> overflow: hidden;>[/color]
------------------^

You are missing the closing quote.

[color=blue]
> <script language="JavaScript"><!--[/color]

The language attribute is deprecated, type is required. HTML comment
delimiters inside script elements are useless and potentially harmful.
[color=blue]
> setTimeout(function()
> {
> var obj,elt;
>
> elt = document.createElement("object");
> elt.setAttribute("width","280");
> elt.setAttribute("height","500");
> elt.setAttribute("type","text/html");
> elt.setAttribute("data","soon.htm");[/color]

You may find it simpler to modify the properties of elt directly:

elt.style.width = '280px';
elt.style.height = '500px';
...


Though it doesn't fix the issue with IE.

[color=blue]
>
> obj = findObj("dummy");
> obj.appendChild(elt);
> },10000);
> //--></script>[/color]

The script should be outside the div that you are trying to reference.
Some browsers may not allow you to get a reference to the div until all
the content is parsed.

[color=blue]
> </div>[/color]


Why not code the object in the HTML, then hide and display it using
script by changing its style object's display or visibility property?
Users without script will see the object directly, if you don't want
that, then hide it in the HTML and know that script-less surfers will
not see it.


<div id="dummy" style="position: absolute; visibility: visible; top:
10px; left: 10px; z-index: 5; height: auto; width: 300px;
padding: 5px; overflow: hidden;">
<object id="obj_01" type="text/html" data="soon.htm" width="280"
height="500"></object>
</div>

<script type="text/javascript">

var obj = findObj('obj_01');
if (obj && obj.style) {
obj.style.visibility = 'hidden';
setTimeout(function() {
obj.style.visibility = 'visible';
}, 60000);
};

// Just for the exercise.
function findObj (id){
return document.getElementById(id);
}

</script>


--
Rob
Asterbing
Guest
 
Posts: n/a
#5: Dec 1 '05

re: Add OBJECT in DIV


In article <MUqjf.168$Hs.13635@news.optus.net.au>, rgqld@iinet.net.au
says...[color=blue]
> Asterbing wrote:[color=green]
> > In article <MPG.1df82f045394a68798971a@news.tiscali.fr>, no@thanks.com
> > says...
> >[color=darkred]
> >>Hi. I'm trying to add an OBJECT in an existing DIV after a certain
> >>delay.
> >>
> >>[/color]
> >
> >
> > OK, done... Uless that the html file which has to be loaded in the
> > created <object> tag is well loded under Netscape 7 but not under IE6
> > nor Opera : the object remains empty (without soon.htm rendered).
> >
> > Here is the new code :
> >
> > <div id="dummy" style="position: absolute; visibility: visible; top:
> > 10px; left: 10px; z-index: 5; height: auto; width: 300px; padding: 5px;
> > overflow: hidden;>[/color]
> ------------------^
>
> You are missing the closing quote.
>
>[color=green]
> > <script language="JavaScript"><!--[/color]
>
> The language attribute is deprecated, type is required. HTML comment
> delimiters inside script elements are useless and potentially harmful.
>[color=green]
> > setTimeout(function()
> > {
> > var obj,elt;
> >
> > elt = document.createElement("object");
> > elt.setAttribute("width","280");
> > elt.setAttribute("height","500");
> > elt.setAttribute("type","text/html");
> > elt.setAttribute("data","soon.htm");[/color]
>
> You may find it simpler to modify the properties of elt directly:
>
> elt.style.width = '280px';
> elt.style.height = '500px';
> ...
>
>
> Though it doesn't fix the issue with IE.
>
>[color=green]
> >[/color][/color]

Thanks for the differents advices, but I can't hard-code this html part
in an hidden div just because this html part will differ from time to
time (says, every 10 mn), then it was because of this I had to reload a
different object's data using timeout.

Well, however, I've searched using Google and it seems it's an object
tag issue which doesn't allow to change data on fly in all browsers.

The solution is just to use iframe rather than object and modify its src
: that way, it works !
Closed Thread