...

View Full Version : site should not working on host server !!!!!!!!!



hansan
06-09-2010, 06:15 AM
Hi,

I have designed a site. It's working properly in locally.



Now I want to insert a special javascript on my home page.



The job of that special javascript is, makes some errors in the site when site is going to publish on internet.


The site should run on locally but not on server
I know that's a strange requirement :(. But that's a test for me...:confused:

Is there any, this kind of special javascript...???
please help me.

thanx

gusblake
06-09-2010, 01:31 PM
This should work: var local=window.location.href.indexOf("http://");

hansan
06-09-2010, 02:03 PM
thanx gusblake.

where should i use that code, in header?
and this code should use only in the home page or should it use in all the pages in site?

gusblake
06-09-2010, 02:15 PM
You would use it like this:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
<script type="text/javascript">
var local=window.location.href.indexOf("http://");
</script>
</head>
<body>
<script type="text/javascript">
if(local) {
//code goes here
}

else {
throw("Execution on remote hosts is disabled for some reason");
}
</script>
</body>
</html>


The code in the head sets the "local" variable to 0 (equal to false) if the URL starts with http://, or -1 or a positive value (equal to true) if it doesn't, so put it in any page that needs to know whether it is local or not. Alternatively, put it in a separate local.js file and use <script type="text/javascript" src="local.js"></script> in the head.

The else block can be used if you want to actually create an error; if you take it out the code will just be skipped silently.

hansan
06-09-2010, 03:04 PM
thank you very much gusblake :)
i'll try this coding.

thnx again

randomuser773
06-09-2010, 06:58 PM
This should work: var local=window.location.href.indexOf("http://");
It should be noted that if the user is running on a local server, then typically the url might be http://localhost/.... so in that situation it would be better simply to search location.href the domain name.

hansan
06-10-2010, 06:12 AM
will it be work when using

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
instead of using,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

Dean440
06-10-2010, 06:46 AM
The DTD shouldn't matter. If you're testing on your local machine via http://localhost or 127.0.0.1, this will work. You can also check for the "file://" protocol at the beginning of the URL to help be sure.


var myURL = window.location.href;
var patt1 = /localhost/i;

if(patt1.test(myURL) || myURL.indexOf("127.0.0.1") != -1 || myURL.indexOf("file://") != -1 ){
alert("You're local.");
}
else{
alert("We don't like your type around here.");
}

hansan
06-15-2010, 05:08 AM
Oh! gusblake, this code is not working at all.even in the locally.
when i use this, it doesn't show anything in locally.
I have check this several times. but it doesn't.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>test</title>
<script type="text/javascript">
var local=window.location.href.indexOf("http://");
</script>
</head>
<body>
<script type="text/javascript">
if(local) {

This is a testing

}

else {
throw("Execution on remote hosts is disabled for some reason");
}
</script>
</body>
</html>

and Dean440 your code also not working, this also doesn't show anything in locally


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>test</title>
<script type="text/javascript">
var myURL = window.location.href;
var patt1 = /localhost/i;
</script>
</head>
<body>
<script type="text/javascript">

if(patt1.test(myURL) || myURL.indexOf("127.0.0.1") != -1 || myURL.indexOf("file://") != -1 ){

This is a testing

}
else{
alert("We don't like your type around here.");
}
</script>
</body>
</html>

IS THIS A MISTAKEN OF MINE??? OR ERROR IN THE CODE???
please help me......

.

hansan
06-16-2010, 07:18 PM
Hello javascript people, aren't there any suggestion for this matter ???

Dean440
06-16-2010, 07:39 PM
if(local) {

This is a testing

}
Is what you have there literally what the code is? In order to get some feedback about what's going on, you would want to alert or print something out.

hansan
06-17-2010, 05:18 AM
actually want I want is, put in to big code within that if function. like,
http://home.comcast.net/~jscheuer1/side/vfs/test_test/test.htm

but before that I wanted to test that code. that is why I was going to display very simple word. but it also didn't work.
so can you help me..........

hansan
06-18-2010, 09:01 PM
Oh! i'm very confusing. there is no one to answer me....
can anyone tell me what is the wrong with that code.
javascript people, please help me... this is a urgent

thank you very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum