Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts

    site should not working on host server !!!!!!!!!

    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...

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

    thanx
    Last edited by hansan; 06-09-2010 at 06:23 AM.

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    This should work: var local=window.location.href.indexOf("http://");

  • Users who have thanked gusblake for this post:

    hansan (06-09-2010)

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    You would use it like this:

    Code:
    <!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.

  • Users who have thanked gusblake for this post:

    hansan (06-09-2010)

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thank you very much gusblake
    i'll try this coding.

    thnx again

  • #6
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by gusblake View Post
    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.

  • Users who have thanked randomuser773 for this post:

    hansan (06-10-2010)

  • #7
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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">
    Last edited by hansan; 06-10-2010 at 06:16 AM.

  • #8
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    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.

    Code:
    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.");
    }
    Last edited by Dean440; 06-10-2010 at 06:49 AM.

  • #9
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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......

    .
    Last edited by hansan; 06-15-2010 at 05:10 AM.

  • #10
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hello javascript people, aren't there any suggestion for this matter ???

  • #11
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Code:
    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.

  • #12
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    actually want I want is, put in to big code within that if function. like,
    http://home.comcast.net/~jscheuer1/s..._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..........

  • #13
    New Coder
    Join Date
    Jun 2010
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •