473,662 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript modification of IE's CSS expression

How, using javascript, can you set or change a CSS value
from something to something else which has the IE
proprietary format: expression(java sriptCode)?
I'd like to know the answer in general, but the specific
issue motivating this is that I have an image in a TD
which I am able to nicely align left/right/center/top
bottom/middle and set (stretch) to various sizes.

I'd like to be able to set the image size as a percent
of the enclosing TD (and other more complicated
scenarios). In IE, setting imgElem.style.h eight
makes the image get stuck to the top (though sized
correctly).

So I have the idea that I could make imgElem.height be
an expression for IE and calculate the actual height
that I want the image to be. Now, I agree that I
could store the necessary multiplicative factor in
a window.heightFa ctor variable, or better yet, have a
dummy function that the expression points to (as in
the example below), but is that really the best way
to go???
Any ideas?
Thanks,
Csaba Gabor from Vienna

PS, for those who haven't seen it, here's a simple
example of this expression business (only works with IE):
<body style="margin:0 ">
<script type='text/javascript'>
function process(value) {
if (value.charAt(v alue.length-1)!="%")
return value;
var img=document.ge tElementById('i mg');
return(img.offs etParent.offset Height *
value.substring (0,value.length-1) / 100);
}
</script>
<form action=''>
<table border style="height:1 00%">
<tr><td style="height:5 %">Enter ratio:
<input type=text name=foo></td></tr>

<tr><td valign=bottom align=center><i mg id=img
style="height:e xpression(proce ss(document.for ms[0][0].value))"
src='pic.jpg'></td></tr>
</form>
</body>

Note that if you leave out the 'process' in that expression, then as
you put in the '%' of 50% that the image will be sized at 50%, but
blasted to the top of the TD.
Jul 23 '05 #1
3 4546
The following script doesn't answer my question of
how to set an expression(java scriptExpressio n) onto
a style element, but I think it is a little more
instructive than my previous example. Note that the
expression has nothing to couple it to the variable
window.fooVal. Indeed, even the 'process' function
is missing it and yet the updating is still immediate
(type in: 50%). This would seem to indicate a huge
amount of computational overhead. I'm supposing
that if any events trigger, expressions reevaluate.

Csaba

<body style="margin:0 ">
<script type='text/javascript'>
var fooVal="200";
function process() {
var value = window['foo'+'Val'];
if (value.charAt(v alue.length-1)!="%") return value;
var img=document.ge tElementById('i mg');
return(img.offs etParent.offset Height *
value.substring (0,value.length-1) / 100);
}
</script>
<form action=''>
<table border style="height:1 00%">

<tr><td style="height:5 %">Enter ratio:
<input type=text
name=foo onPropertyChang e="window.fooVa l=this.value"></td></tr>

<tr><td valign=bottom align=center><i mg id=img
style="height:e xpression(proce ss())" src='pic.jpg'></td></tr>

</table>
</form>
</body>
Jul 23 '05 #2
OK, I finally have it - setExpression allows
you to set an expression on a style property
on the fly with javascript (see also
removeExpressio n and document.recalc ):
<body style="margin:0 " onLoad="init()" >
<script type='text/javascript'>
var tbVal="200";
function elem(id) {
return document.getEle mentById(id);}
function process() {
var value = window.tbVal;
if (value.charAt(v alue.length-1)!="%") return value;
var img=document.ge tElementById('i mg');
return(img.offs etParent.offset Height *
value.substring (0,value.length-1) / 100);
}

function init() {
var iStyl = elem('img').sty le;
iStyl.setExpres sion("height"," process()");
elem('tbIn').fo cus();
}
</script>
<form action=''>
<table border style="height:1 00%">

<tr><td style="height:5 %">Enter ratio:
<input type=text tabIndex=1 id=tbIn name=tbIn
onPropertyChang e="window.tbVal =this.value"></td></tr>

<tr><td valign=bottom align=center><i mg id=img
src='pic.jpg'></td></tr>

</table>
</form>
</body>
Csaba Gabor from Vienna
Jul 23 '05 #3
*** Csaba Gabor wrote/escribió (Mon, 14 Mar 2005 23:25:29 GMT):
id=img
style="height:e xpression(proce ss(document.for ms[0][0].value


I'd try something like:

document.getEle mentById('img') .style.height=d ocument.forms[0][0].value+'%';

If it works, you can get rid of the proprietary IE extension. If you're to
publish a web site that only works in Windows IE, you'd better write a real
app in VisualBasic or C++ ;-)
--
-- Álvaro G. Vicario - Burgos, Spain
-- Don't e-mail me your questions, post them to the group
--
Jul 23 '05 #4

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

Similar topics

3
1239
by: MrPutty | last post by:
Hello, I've aquired some Javascript that will kick in when a IE version < 6 comes to visit. It positions elements with a position:fixed effect. I need to add control for one more div container. Problem is - I don't have a clue about Javascript. This is the complete sheet: html, body{ background:url(foo) fixed;} #head, #footer, #navigation_oben{ position:absolute;
0
8435
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
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
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
7368
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
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
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
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
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.