0

IE Conditional Comments in zul files

asked 2010-05-19 04:34:45 +0800

myzkdemo gravatar image myzkdemo
154 3

Hello,

I have a requirement that needs different style definitions for the different browsers. In XHTML it is possible to use "IE Conditional Comments" (eg. <!--[if IE]> Internet Explorer <![endif]-->)

If I try this in a zul-File the comments are ignored.

Here are my example:

<zk>
<style>
	.bg-div {background: green; margin: 10px}
</style>

<!--[if IE]>
<style>
	.bg-div {background: red; margin: 10px}
</style>
<![endif]-->

<div sclass="bg-div" width="100%" height="500px" />

</zk>

thanks and regards,
Gunter

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2010-05-19 07:34:47 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi Gunter
I create a sample

<zk>
	<style if="${execution.explorer}">
		.myLabel {
			color: blue;
		}
	</style>
	<style unless="${execution.explorer}">
		.myLabel {
			color: red;
		}
	</style>
	<label value="test" sclass="myLabel"/>
</zk>

and you can refer to java doc

link publish delete flag offensive edit

answered 2010-05-19 09:40:50 +0800

myzkdemo gravatar image myzkdemo
154 3

Hi Jimmy,

great! It works.

Many thanks,
Gunter

link publish delete flag offensive edit

answered 2011-01-28 07:30:32 +0800

florimon gravatar image florimon
9

This post was really helpful, but I had a need to test specifically for IE6 - and org.zkoss.ui.Execution and org.zkoss.ui.http.ExecutionImpl only have an isExplorer() and an isExplorer7() method.
Those classes do contain a generic "boolean getTypeOfBrowser(String)" method, but alas because of that signature you can't use it from an EL expression - EL relies on maps for indexed properties.
After some tinkering, I came up with the following additional method that I added to my local copies of ExecutionImpl.java class and Execution.java interface :

	@SuppressWarnings("serial")
	public Map<String, Boolean> getBrowserType() {
		return new HashMap<String, Boolean>() {
			@Override
			public Boolean get(Object type) {
				return isBrowser((String) type);
			}
		};
	}

With this in place, you can now use EL expressions like
    if="${execution.browserType.ie6}"

or

    if="${execution.browserType['ie6']}"

link publish delete flag offensive edit

answered 2011-02-05 03:10:58 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi florimon,
Here are another sample

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<zk>
gecko: ${c:isGecko()}
<separator/>
gecko2: ${c:browser('gecko2')}
<separator/>
gecko3: ${c:isGecko3()}
<separator/>
ie: ${c:isExplorer()}
<separator/>
ie7: ${c:isExplorer7()}
<separator/>
ie8: ${c:browser('ie8')}
<separator/>
safari: ${c:isSafari()}
<separator/>
opera: ${c:isOpera()}
<separator/>
</zk>

link publish delete flag offensive edit

answered 2012-03-20 16:45:27 +0800

huubf gravatar image huubf
69 1

updated 2012-03-20 16:46:25 +0800

great thanks
id used it like
<script if="${c:browser('ie6')}" src="IE6version.js"></script>
<script if="$" src="LongScript.js"></script>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-05-19 04:34:45 +0800

Seen: 1,387 times

Last updated: Mar 20 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More