473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

CSS Expression with if/else

Hi,

Is it possible to use expressions in CSS with if/else statements?

I am trying to dynamically resize and iframe using the following CSS:

<style>
iframe {height:expression(if(document.readyState=='comple te')frames("myIframe").document.body.scrollHeight+ 25);}
</style>

This code waits until the iframe src page to load before calculating
the height. This solves some problems that come up when it tries to
calculate the hieght on a partially loaded src. Anyway, this works
okay, but when pages take a long time to load, only a fraction of the
page is displayed until it is completely loaded. Is there any way to
put the following code in an expression?

if (document.readyState=='complete') {
frames("winPanel").document.body.scrollHeight+25);
} else {
5000;
}

Basically, the problem is that CSS interprets the characters ;, {, and
} as CSS notation, so I don't know if I can use these characters in an
expression. Is there any way to solve this?

Thanks,

Jim
Jul 23 '05 #1
3 14145
ji*@marqorp.com (Jim Marquardson) writes:
Is it possible to use expressions in CSS with if/else statements?
This newsgroup is not about CSS, but ... no.
I am trying to dynamically resize and iframe using the following CSS:

<style>
The "type" attribute is required, so use:
<style type="text/css">
iframe {height:expression(if(document.readyState=='comple te')frames("myIframe").document.body.scrollHeight+ 25);}
</style>
That might work in IE, but not in any other browser. Using "expression" in
CSS is a proprietary IE extension (as is "document.readyState").

I don't know how "expression" works in IE (is it updated when the involved
variables change?).

Maybe you can use a conditional expression. In Javascript, as inherited
from C, it is written:
<condition> ? <expression-if-true> : <expression-if-false>

This code waits until the iframe src page to load before calculating
the height.
Nope, it waits until *this* document has finished loading before
accessing the frames document (if I read it correctly, I'm not sure
what "readyState" means either).

if (document.readyState=='complete') {
frames("winPanel").document.body.scrollHeight+25);
} else {
5000;
}
Try
((document.readyState=="complete") ?
farmes["winPanel"].document.body.scrollHeight + 25 : 5000)
Basically, the problem is that CSS interprets the characters ;, {, and
} as CSS notation, so I don't know if I can use these characters in an
expression.


They are not part of a Javascript *expression*, but a Javascript
*statement*. The above notation is a conditional expression, just as
"if" is a conditional statement.

/L 'but don't make pages that only work in IE'
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
I have a similar issue, but have sort of solved it using a JavaScript
function on the onreadystatechange event for the iframe. The only
problem is that there are 4 readyStates, and with 10+ iframes on the
page, there is no guarantee that the onreadystatechange events fire
quick enough so that when I set the height of the iframe, the
readyState=='complete' (ie the page in the iframe has finished loading).

So, I have introduced a wait-loop (which is a kludge). However, I may
try out the css options mentioned above.

Thanks.

1+0 :-)

function adjust_frame_height(frame_id,container) {
var repeat = 5;

setTimeout("repeated_adjust_frame_height("+frame_i d+","+container+","+re
peat+")",250);
}

function repeated_adjust_frame_height(frame_id,container,re peats) {
var next_repeat = repeats - 1
try {
var tempheight = 24;
if
(document.getElementById(frame_id).contentWindow.d ocument.readyState=="c
omplete") {
document.getElementById(frame_id).height =
(document.getElementById(frame_id).contentWindow.d ocument.getElementById
(container).offsetHeight);
if (document.getElementById(frame_id).height == 0) {
document.getElementById(frame_id).height =
tempheight;
}
} else {
if (next_repeats > 0) {

setTimeout("repeated_adjust_frame_height("+frame_i d+","+container+","+ne
xt_repeat+")",200);
} else {
if (document.getElementById(frame_id).height == 0) {
document.getElementById(frame_id).height =
tempheight;
}
)
)
} catch(e) {
// Wait and then try again...
)
}
}


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Thanks for the advice. I ended up using the advice Lasse gave about
using a conditional expression. So, here's the CSS code that takes
care of the iframe height problem:

iframe {height:expression(document.getElementById('winPan el2').readyState=='complete'
? frames("winPanel2").document.body.scrollHeight+25 : 20000);}

Another option I considered using was the following:

<style>
iframe {height:expression(getHeight());}
</style>
<script>
function getHeight() {
if (document.getElementById('winPanel2').readyState== 'complete') {
return frames("winPanel2").document.body.scrollHeight+25;
} else {
return 20000;
}
}
</script>

But, that takes several lines to do what I can now do in one. So, I
prefer the one line solution.

I realize that this will only work in IE, but since I'm designing the
pages for an intranet where everybody uses IE, it should work fine.

Thanks,

Jim
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris | last post by:
Hi Folks, I would like to forward an expression to an if-statement via a variable. Like: $a=10; $b=20; $expr="$a > $b";#this should be my if-expression if ($expr) do something;#test should...
23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
2
by: cool17 | last post by:
#include "expression.h" #include <stdlib.h> #include <stdio.h> #include <string.h> xContainer splitTerm(string,int,int);
3
by: Frank Swarbrick | last post by:
I was just messing around trying to learn things and attempted the following: select brch_nbr , sum(case when post_flag != 'P' then amount else 0 end) as sum_amount from film.film_transactions...
20
by: TimeHorse | last post by:
I would like to gauge interest in the following proposal: Problem: Assignment statements cannot be used as expressions. Performing a list of mutually exclusive checks that require data...
1
by: jelling | last post by:
Hi, Is it possible to use a CASE or IF ELSE statement in a datacolumn expression? Here's what I've tried: 'standardCodeColumn.Expression = "CASE StandardsBodyID WHEN 1 THEN 'JCAHO' ELSE...
6
by: eureka2050 | last post by:
Hi, I am a PHP coder, recently ran into a bit of a problem trying to evaluate expressions in PHP. I have an expression which is stored in a string variable and when I try to evaluate it, it...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.