Solved

Size of navigator visual basic

Posted on 2014-07-25
3
416 Views
Last Modified: 2014-07-27
I'm using this code

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
 
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 window.alert( 'Width = ' + myWidth );
 window.alert( 'Height = ' + myHeight );

Open in new window


   The code is in JavaScript and detect the browser dimensions now I have these questions:

1.-Is there a way to use the same in Visual basic. if yes could you paste the code here?
2.-Is there a way to pass a variable from JavaScript to Visual basic if yes how with examples. For example in the above example the variable "Width" suppose has a value of 500 in JavaScript how can I pass that value to that  JavaScript variable "Width" with same name or another no matter. Is allowed use session variables I can generate from visual basic (vbscript) the session variable then load in JavaScript I can do that but after modified the session variable how can I return to visual basic is the same ti send a variable from JavaScript to Visual Basic (vbscript) I don't know how.

This is for a simple ".asp" pages I'm not using ASP.NET

Thank you

Edit by Padas:  Should be vbscript and not Visual Basic
0
Comment
Question by:coerrace
3 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40221058
1.-Is there a way to use the same in Visual basic. if yes could you paste the code here?
No, Vbscript is a server side language.  Detecting the browser width is done in javascript.

2.-Is there a way to pass a variable from JavaScript to Visual basic if yes how with examples.
There is,  however you can't use it in the way you are thinking.  The way your page renders is first any of your vbscript is run ON THE SERVER.  This means any calculations, database calls and rendering of html.  Next the vbscript rendered html is merged with your static html and the full html page is rendered to the browser.  Finally, any javascript or jquery you have written will be executed.  This includes things like detecting the browser width, changing any css or adding/changing/removing/hiding/showing any elements.

This means you could have a field like,
<input id="abc" name="abc" value=""> 

Open in new window

and set it with js like
document.getElementById('abc').value = 'my_value';

Open in new window

or in jquery
$('#abc').val('my_value');

Open in new window

Now once the page is fully rendered (with javascript turned on) the input will look like below if you use your browsers console (view source will still look as hard coded)
<input id="abc" name="abc" value="my_value"> 

Open in new window

When you submit the above, you can get the value by using
response.write request.form("abc")

Open in new window

My guess is if you need to change something based on width detected  from javascript or jquery, then you should also update whatever element you are trying to target with jquery as well.

You can also use Media Queries in  your css https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

Let's say you have

<style>
div.foo{
   width:800px;
}
</style>
<div class="foo">Bar</div>

Open in new window

But that is too big for a 700px screen.  You can use media queries to set css for different viewports.
<style>
div.foo{
   width:800px;
}
@media (max-width: 800px) {
    div.foo{
        width:700px;
   }
}
@media (max-width: 700px) {
    div.foo{
        width:600px;
   }
}
</style>
<div class="foo">Bar</div>

Open in new window


Using a combination of javascript/jquery and css/media queries, you have a lot of options.  If by chance you are trying to build a responsive site, look into using http://getbootstrap.com/ or http://foundation.zurb.com/ as your core.  These are both responsive css grid systems with some extra responsive help.  

Please let me know if I missed something or your question is different than I guessed.
0
 

Author Closing Comment

by:coerrace
ID: 40222726
Excellent answer thank you for the time
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now