Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2012, 02:35 PM
RedTurtle's Avatar
RedTurtle RedTurtle is offline
 
Join Date: May 2006
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Screen Resolution Conditional to Wrap Around Some Template Code?

Hi guys,

I have a specific part of my website that messes up if someone with a screen resolution lower than 1280x800 looks at it. I know that resolution isn't very common, but it is still out there, especially in Asia where a large part of my users visit from.

I am looking for having some conditional that I can use where it checks the screen width and if its greater than or equal to 800px, then it shows some code, otherwise it doesn't.

How could I accomplish this? Thank you for any help or insight you can provide. I appreciate you taking the time to read this and assist me!
Reply With Quote
  #2  
Old 12-08-2012, 03:10 PM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's not that easy. PHP code (and template preparation) is executing on server-side, before sending the output to user (client-side). So you need to find a Javascript script to do it. I'll look on my library to see what I can find. I've added such Javascript in my Classifieds mod.

Chris
Reply With Quote
  #3  
Old 12-08-2012, 03:22 PM
RedTurtle's Avatar
RedTurtle RedTurtle is offline
 
Join Date: May 2006
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for your help Chris!

If you could find something that would work I would really appreciate it.

Thanks again for responding -- your explanation did make sense to me.
Reply With Quote
  #4  
Old 12-08-2012, 03:39 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Java Scrpit for check user's screen

var screenWidth = window.screen.width,
screenHeight = window.screen.height;
Reply With Quote
  #5  
Old 12-08-2012, 03:42 PM
RedTurtle's Avatar
RedTurtle RedTurtle is offline
 
Join Date: May 2006
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by mokujin View Post
Java Scrpit for check user's screen

var screenWidth = window.screen.width,
screenHeight = window.screen.height;
Thank you mokujin for responding.

How would I implement this in vB4 so that I could show some code only if the screen width was at least 800px wide?

Thanks again.
Reply With Quote
  #6  
Old 12-08-2012, 06:17 PM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I need some more infor to understand what you're trying to do after getting user's screen resolution. Redirecting to another page, ...or displaying different code (eg {vb:raw short_screen} instead of {vb:raw wide_screen}) etc

--------------- Added [DATE]1354994447[/DATE] at [TIME]1354994447[/TIME] ---------------

Quote:
Originally Posted by mokujin View Post
Java Scrpit for check user's screen

var screenWidth = window.screen.width,
screenHeight = window.screen.height;
You know how to use it, me too eighter. But a non-coder trying to put it as is in the template he will mess everything.
Reply With Quote
  #7  
Old 12-08-2012, 06:24 PM
RedTurtle's Avatar
RedTurtle RedTurtle is offline
 
Join Date: May 2006
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ChrisTERiS View Post
I need some more infor to understand what you're trying to do after getting user's screen resolution. Redirecting to another page, ...or displaying different code (eg {vb:raw short_screen} instead of {vb:raw wide_screen}) etc
Thanks for responding!

I have two 300x250 adblocks show up on my forum's main page right now to guests who visit.

If a user has a screen resolution of less than 800px, I would only like to show one adblock.

So something like:

Code:
first adblock code <if screen width 800px or more> second adblock code </if>
Reply With Quote
  #8  
Old 12-08-2012, 06:43 PM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, assuming that you've a bit HTML knowledge so you can add each code to a seperate "div", follow the steps:

1.- Add to headinclude template:
Code:
<script type="text/javascript">
function SetResState()
{
    if(screen.width <= 800)
    {
        document.getElementById('adcode1').style.display = 'block';
        document.getElementById('adcode2').style.display = 'none';
    }
    else
    {
        document.getElementById('adcode1').style.display = 'block';
        document.getElementById('adcode2').style.display = 'block';
    }
}	
</script>
The above Javascript code checks at client-side the user's screen resolution. If it's <= 800 then activates only the "div" adcode1 and hides the adcode2. If the resolution is hogher than 800 then activates both blocks. Offcourse you can change the minimum resolution. eg to 1024.

2.- On the SHELL template change the BODY to:
HTML Code:
<body onload="SetResState()">
3.- Now in your template you need to create 2 blocks. One will holds the adcode for A product, and the other the adcode for B product:
HTML Code:
<div id="adcode1" style="display: none;">
..........Code for Ad 1.............
</div>
<div id="adcode2" style="display: none;">
..........Code for Ad 2.............
</div>
!!!! Please be aware that I did a change to Javascript code. This one now is the correct.

I've tested it at: http://www.christeris.com/adblocks.html and works


Chris
Reply With Quote
  #9  
Old 12-08-2012, 06:53 PM
RedTurtle's Avatar
RedTurtle RedTurtle is offline
 
Join Date: May 2006
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you Chris!

I will try this a little later today and let you know how it went!
Reply With Quote
  #10  
Old 12-09-2012, 05:34 PM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by RedTurtle View Post
Thank you Chris!

I will try this a little later today and let you know how it went!
So? Does it works as you expected to?

Chris
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04461 seconds
  • Memory Usage 2,261KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_html
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete