General discussion

Locked

javascript and resize windows

By eb_alavi ·
I have 2 question :
1- I want create an HTML page with javascript .
And I want when user resize window ,
I refresh page again How can I ?
2- I have an string variable in javascript I want to search in it and find some word.
I mean I want a function like INSTR in vbscript.
thanks

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by dem_ In reply to javascript and resize win ...

hi,

I will provide a solution to the first question.

The follow will resize the browser window to 600x600 and postion it in the center of the screen. You can replace 600 with any other value
or screen.availWidth and screen.availHeight to maximize the window.

self.resizeTo(600,600)
self.moveTo(((screen.availWidth-600)/2),((screen.availHeight-600)/2))

Next you can reload the document if the user resizes using the following:

if (document.all && document.resize) document.URL=location.href; // Microsoft IE

if (document.layers && window.resize) window.location.href = window.location.href; // Netscape

regards.

Collapse -

by dem_ In reply to javascript and resize win ...

hi,

I am not big on vbscript at this time but quite
familiar with Javascript. I believe I have a solution for the 2nd question.

To search for a string within a string or word. You can very well replace the "@" with a word or phrase.

This simple email validate function checks within a form input for the "@" symbol and responds with a valid/invalid message.


This should be place within the "script" tags.
function valid(obj)
{
if (obj.value.indexOf("@") != -1)
{
obj.value="valid input";
obj.focus();
return true;
}
else
{
obj.value="invalid input";
return false;
}
}


this should be placed within the BODY tags.
<input type="text" name="email" value="" onchange="valid(this)">

Hope this is what you are looking for.

regards

Collapse -

by eb_alavi In reply to

try this code for substring
function search(target,term,caseSens,wordOnly){
//target=targetSting , term=substring
// For example
// strA="Hi how are you";
// strB="ho";
// var check=search(strA,strB,0,0);
// if strb found check = true
var ind=0;
var next=0;
if (!caseSens){
term=term.toLowerCase();
target=target.toLowerCase();}
while ((ind=target.indexOf(term,next))>=0){
if (wordOnly) {
var befor=ind-1;
var after=ind+term.length;
if(!(space(target.charAt(before))&&space(target.charAt(after)))){
next=ind+term.length;
continue;}
}
return true;
}
return false;
}
function space(check){
var space=".,/<>?!`':;@#$%^&*()=-|[]{}"+'"'+"\\n\t";
for (var i=0;i<space.length;i++)
if (check==space.charAt(i)){return true;}
if (check=="") {return true;}
if (check==null){return true;}
return false;
}


function runMenu(strURL){
var a=search(strURL,"totalcompanies",0,0);
if (a) { //Do something }
}

Collapse -

by eb_alavi In reply to javascript and resize win ...

This question was closed by the author

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums