I need to know the width of the browser window in an xslt macro, for some image scaling.
So i thought i could just use some javascript, but i guess the xslt is compiled before the javascript is rendered so that won't work... My idea was like this:
Is there a way to get the width of the browser window, so it can be used as an xsl:variable? Ive been toying with different ideas for a couple of days now, but i guess its time to ask the experts ;).
You're right - the XSLT has no way of knowing which size of window the rendered content will end up in. You could of course run a snippet of JavaScript on the first request and then set a cookie, which you could then read in your XSLT - but again, it's not really the right place to deal with it...
What's the scenario like? Wouldn't you be able to use media queries or something similar to achieve the same result?
Its actually for a responsive site using eksponent cropup. The site uses a series of looping images which fill the browser window. I would like to server scale the images to match the browser window to save as much bandwidth as possible. Especially on mobile.
I tried the cookie approach, but it requires a reload of the page to read the cookie. You can't set and read the cookie on the same page load...
Any ideas? i looked a bit at msxsl:script, but cant realy see if it would make any diff?!?
Yeah, I didn't explain the cookie thing good enough - but that's what I meant with the "first request" - but if you need the value on the front page, you won't be able to get it before too late :-)
Anyways, - did you look into the responsive extensions that's available with CropUp? They might be exactly what you need... (I haven't tried them myself, so can't really say)
So here's how I'd probably do it: Use media queries for the "breakpoints" and have CropUp serve images in those sizes, and then use width: 100%; height: auto; in the CSS to have those images scale to the window. This will only "punish" thoose that open a small window, load the site and then resize their window to the largest size - they will of course get upscaled images, but as soon as they click a link (and how long does that take for the average user? :-) they will get properly sized images.
Actually - I think that's some of what the responsive CropUp extensions do - but they probably also detect the resize event for reloading the new sizes... (I may be way off, though)
Yeah i follow you. But there are a couple of strange things going on with the cropup responsive. I know it's Nils i have to turn to concerning this, but ill just metion it for good measure.
Getting the width of a browser window
I need to know the width of the browser window in an xslt macro, for some image scaling.
So i thought i could just use some javascript, but i guess the xslt is compiled before the javascript is rendered so that won't work... My idea was like this:
Is there a way to get the width of the browser window, so it can be used as an xsl:variable?
Ive been toying with different ideas for a couple of days now, but i guess its time to ask the experts ;).
Hi Claus,
You're right - the XSLT has no way of knowing which size of window the rendered content will end up in. You could of course run a snippet of JavaScript on the first request and then set a cookie, which you could then read in your XSLT - but again, it's not really the right place to deal with it...
What's the scenario like? Wouldn't you be able to use media queries or something similar to achieve the same result?
/Chriztian
Its actually for a responsive site using eksponent cropup. The site uses a series of looping images which fill the browser window. I would like to server scale the images to match the browser window to save as much bandwidth as possible. Especially on mobile.
I tried the cookie approach, but it requires a reload of the page to read the cookie. You can't set and read the cookie on the same page load...
Any ideas?
i looked a bit at msxsl:script, but cant realy see if it would make any diff?!?
Yeah, I didn't explain the cookie thing good enough - but that's what I meant with the "first request" - but if you need the value on the front page, you won't be able to get it before too late :-)
Anyways, - did you look into the responsive extensions that's available with CropUp? They might be exactly what you need... (I haven't tried them myself, so can't really say)
So here's how I'd probably do it: Use media queries for the "breakpoints" and have CropUp serve images in those sizes, and then use width: 100%; height: auto; in the CSS to have those images scale to the window. This will only "punish" thoose that open a small window, load the site and then resize their window to the largest size - they will of course get upscaled images, but as soon as they click a link (and how long does that take for the average user? :-) they will get properly sized images.
Actually - I think that's some of what the responsive CropUp extensions do - but they probably also detect the resize event for reloading the new sizes... (I may be way off, though)
/Chriztian
Yeah i follow you. But there are a couple of strange things going on with the cropup responsive. I know it's Nils i have to turn to concerning this, but ill just metion it for good measure.
Which is a bit heavy. And it seems to load both a large image and a small one every time... This im not totally sure about tthough...
All in all, if it could do the height:100% and width:100%, all would be pretty good :)
Ok, i went down the cookie route, and got it fixed. A bit hackish, but it works.
First i check if the cookie value is equal to the window width. If not i set the correct cookie value and force reload the page.
Then i can use the cookie value to scale the image to fit the window.
is working on a reply...