Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bad object reference

Status
Not open for further replies.

pahiker

Programmer
Aug 31, 2012
45
US
I have a script trying to change the height in an object tag. It is working in most browsers but a few, like IE7 are tossing an error:
06935e8a436b5431101579b3384e8452.png


Here is the script, the line with the obj.height is what is causing the problem. I tried changing the setting of obj to getElementByTagName and it works (no error message) but the object on the main page doesn't resize in any browser.

Here is the script:
Code:
function loaded() {
	var body = document.body,
		html = document.documentElement;
	var s = Math.max(body.offsetHeight, html.scrollHeight, html.offsetHeight);
	var obj = document.getElementById("objContent");
	obj.height = s + 10;
}


Here is a snippet of the main page with the div containing the object:
Code:
<div id="divContent" class="left">
	<object id="objContent" data="Home/Prayer.html" width="100%" height="100%" type="text/html"></object>
</div>

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
getElementByTagName is actually getElementsByTagName('tag') and createa an arrary of ALL the <tag> elements in the document.

Where are you calling the script from?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Better still; give us a URI so we can go look for ourselves.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 

I thought that getElementById returned a single occurrence by Id, which is what I was trying for.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
I thought that getElementById returned a single occurrence by Id, which is what I was trying for.
It does


Firefox error console throws up this.

Timestamp: 23/09/2012 00:40:16
Warning: SyntaxError: test for equality (==) mistyped as assignment (=)?
Source File: Line: 46, Column: 21
Source Code:
while(e=allTags[i++]){

------------------------^

IE9 Dev tools throws
SCRIPT5007: Unable to get value of the property 'type': object is null or undefined
reSize.js, line 6 character 2
which is this line
Code:
alert(obj.type);
And there is no 'type' property, there is a typeof property.



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
The = is correct, it is not a comparison, but setting a value. This works.

I tried different properties on the alert, even just obj, nothing works. Obj returns null, for some reason it's not losing the object.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
This is now resolved.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
while(e=allTags[i++]){ Is NOT an assignment it is a comparison

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
The code works, test it. allTags contains the tag name array, the e=allTags[i++] assigns the appropriate element to e, when at the end e contains zero. The while statements fails when e=0 and falls through. Pop it into a program, it works. This changes the eight large buttons (including their text) when one of the top three buttons is click. That works.

Code:
	var allTags = document.getElementsByTagName("*");
	var i=0, l=0;
	var e;
	while(e=allTags[i++]){
		if(e.id.substring(0,4) == "link") {
			if (l < ary.length) {
				e.className = btn;
				e.innerHTML = ary[l][0];
				e.data = ary[l][1];
				e.style.visibility = 'visible';
				l++;
			}
			else {
				e.style.visibility = 'hidden';
			}
		}

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Hi

Chris said:
while(e=allTags[i++]){ Is NOT an assignment it is a comparison
The [tt]while[/tt] needs a value to test for truthness. The assignment results in a value, so it is perfectly usable there.

It is practically the same as :
JavaScript:
[b]while[/b] [teal]([/teal][highlight][teal]([/teal][/highlight]e[teal]=[/teal]allTags[teal][[/teal]i[teal]++][/teal][highlight][teal])[/teal][teal]!==[/teal]undefined[/highlight][teal])[/teal] [teal]{[/teal]

pahiker said:
when at the end e contains zero
You probably mean [tt]undefined[/tt].

Feherke.
[link feherke.github.com/][/url]
 
You probably mean undefined.

Could be, I was going back to my experience with C++, Perl, and Java, where 0=false and <>0 = true.

Regardless, and the overall page code has change since this thread started, IE still doesn't behave with the object code. I'm thinking there is no way to get it to work, and I need to go back to iFrame.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top