LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2011, 07:55 AM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Javascript to verify correct URL


Lets say I have a site "Website1.com"

On that site I want to run a little javascript that verifies that the site was accessed as "Website1.com" and not "dev-Website1.com"

If it was accessed correctly, nothing happens. If it was accessed incorrectly, it displays an error saying "You are trying to access this site incorrectly."

What is the simplest way to accomplish this?
 
Old 05-31-2011, 08:03 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
You can use window.location to get the link to the page. But it is the full link, not just the domain name. So you can check if it contains a word instead. Something like this:
Code:
<script type="text/javascript">

if (window.location.indexOf("dev-Website1.com") >= 0) {
    alert("You are trying to access this site incorrectly.");
    // Maybe do something else as well instead of just showing a message? Then for example
    // window.location = "errorpage.html";
}

</script>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Web browsing fails to load correct URL, ignores /etc/hosts!! Daily issue lefty.crupps Linux - Desktop 6 08-11-2008 02:01 PM
embedding javascript in url mohit dhawan Programming 7 04-07-2006 10:41 AM
How do I verify my locale information is "correct"? TheLinuxDuck General 3 03-02-2006 03:06 AM
Javascript : Importing content from another url synna Programming 0 03-02-2004 11:12 AM
Can you verify a url with php? digitalgravy Programming 4 03-01-2004 01:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration