Solved

Size of navigator visual basic

Posted on 2014-07-25
3
419 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Only allow one site in Internet Explorer on XenApp. 9 51
How to make an ADE file by code? 11 80
Server Timeout with Loop 6 38
Error in query expression 3 37
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

920 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

17 Experts available now in Live!

Get 1:1 Help Now