Size of navigator visual basic

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
coerraceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
coerraceAuthor Commented:
Excellent answer thank you for the time
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.