PDA

View Full Version : get browser width



game
07-13-2013, 07:10 PM
i have a table with 3 td's , the one on center will be 1000px width
so i need to split the remaining pixels for left and right <td>

how can i do this with javascript?

i am using this code to get the exact resolution



<script>
function getDocHeight() {
var D = document;
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
}

function getDocWidth() {
var D = document;
return Math.max(
D.body.scrollWidth, D.documentElement.scrollWidth,
D.body.offsetWidth, D.documentElement.offsetWidth,
D.body.clientWidth, D.documentElement.clientWidth
);
}

alert( getDocHeight() );
alert( getDocWidth() );
</script>


<td><td width=1000px><td>

Beverleyh
07-13-2013, 08:01 PM
I'm not sure why you'd need JavaScript to do this. If its to ensure a centered table with equal outer cells, I think CSS should be enough - you can set both outer td widths to 50% each and they should just take up the available space. Couple that with margin:auto; on the main table to center it (just to be safe, although that shouldn't be necessary) and the result should be a table with a fixed centre cell that is 1000px wide, with each outer cell taking up the remaining width, whatever that is. I haven't tested this exact theory, (currently on iphone) but from experience, that's what behaviour I predict.

If you need more help, please provide a link to your page, with a more detailed description of the project and what/why you're trying to achieve what you've described.

game
07-13-2013, 08:52 PM
i need to do it this way to get the exact with from the members browser because the outer cells will be clickable , adding 50% then the center cell will also become clickable

http://demo.rawcodes.net/

Beverleyh
07-13-2013, 09:14 PM
Im sorry, but I dont understand. Why would the center cell become a clickable link based on a width measurement? If whatever is in the 2 outer cells contains the hyperlink(s), they should not encroach into the center cell; http://fofwebdesign.co.uk/template/_testing/table-center-cell-1000.htm

game
07-13-2013, 09:52 PM
thanks will try this way, is there any chance to make when they click any area in the outer cells it redirects them to another url?

game
07-13-2013, 10:46 PM
i was using this code from http://wordpress.org/support/topic/can-you-make-a-body-background-image-clickable



#bglink{
display:block;
height:100%;
width:50%;
position:fixed;
left:0;
top:0;
z-index:0;
text-indent:-5000em;
/* If you want to make only a part of background clickable,
adjust height/width/left/top here. */
}

#page {
position:relative;
z-index:10;
}

game
07-13-2013, 10:59 PM
got it to work with <td onclick="window.location = 'index.html';">cell content</td>