473,765 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:express ion(if(document .readyState=='c omplete')frames ("myIframe").do cument.body.scr ollHeight+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.ready State=='complet e') {
frames("winPane l").document.bo dy.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 14168
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:express ion(if(document .readyState=='c omplete')frames ("myIframe").do cument.body.scr ollHeight+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.ready State").

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.ready State=='complet e') {
frames("winPane l").document.bo dy.scrollHeight +25);
} else {
5000;
}
Try
((document.read yState=="comple te") ?
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/rasterTriangleD OM.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 onreadystatecha nge 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 onreadystatecha nge events fire
quick enough so that when I set the height of the iframe, the
readyState=='co mplete' (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_he ight(frame_id,c ontainer) {
var repeat = 5;

setTimeout("rep eated_adjust_fr ame_height("+fr ame_id+","+cont ainer+","+re
peat+")",250);
}

function repeated_adjust _frame_height(f rame_id,contain er,repeats) {
var next_repeat = repeats - 1
try {
var tempheight = 24;
if
(document.getEl ementById(frame _id).contentWin dow.document.re adyState=="c
omplete") {
document.getEle mentById(frame_ id).height =
(document.getEl ementById(frame _id).contentWin dow.document.ge tElementById
(container).off setHeight);
if (document.getEl ementById(frame _id).height == 0) {
document.getEle mentById(frame_ id).height =
tempheight;
}
} else {
if (next_repeats > 0) {

setTimeout("rep eated_adjust_fr ame_height("+fr ame_id+","+cont ainer+","+ne
xt_repeat+")",2 00);
} else {
if (document.getEl ementById(frame _id).height == 0) {
document.getEle mentById(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:express ion(document.ge tElementById('w inPanel2').read yState=='comple te'
? frames("winPane l2").document.b ody.scrollHeigh t+25 : 20000);}

Another option I considered using was the following:

<style>
iframe {height:express ion(getHeight() );}
</style>
<script>
function getHeight() {
if (document.getEl ementById('winP anel2').readySt ate=='complete' ) {
return frames("winPane l2").document.b ody.scrollHeigh t+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
1927
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 be if($a > $b)
23
3234
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 there are no assignment expressions in Python, I have to use a temp var. That's a little more messy, but bearable:
3
2300
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 ordinary Lisp S-expression. So it's easy enough to translate some XML into equivalent Lisp. Now I turn it over to the Lisp parser, which creates the equivalent of the DOM for me.
2
1566
by: cool17 | last post by:
#include "expression.h" #include <stdlib.h> #include <stdio.h> #include <string.h> xContainer splitTerm(string,int,int);
3
9766
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 group by brch_nbr having sum_amount 0 order by sum_amount desc ;
20
2139
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 processing can cause excessive tabification. For example, consider the following python snipet...
1
7985
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 'Non-JCAHO' END" 'standardCodeColumn.Expression = "CASE WHEN
6
3944
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 always returns a 'TRUE' Eg: $str = '6.0 >= 8.5' ;
56
6765
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 6.4.2(2) : case constant-expression : I propose that the case expression of the switch statement be changed from "integral constant-expression" to "integral expression".
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.