Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,312 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,709 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



quick question

 
Reply to this topicStart new topic

quick question

JBrace1990
post 28 Jul, 2008 - 12:59 PM
Post #1


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 459



Thanked 20 times

Dream Kudos: 350
My Contributions


i'm having a little problem with this code... whenever I call the function and place in a variable (say login.php), i neither get an alert nor a window change... it's as if the JS doesn't occur =/

yes, i have JS enabled in the browser...
jscript
<script language="JavaScript" type="text/javascript">
//Flex SWF calls
var loc = window.location.split(":",1);
var loc2 = loc[2].split(".",1);
function url(url)
{
if(loc2[0] == "//www"){
alert("1")
window.location = "http://www.ultimatebaseballsim.com/"+url+"";
}else{
alert("2")
window.location = "http://ultimatebaseballsim.com/"+url+"";
}
}
//end Flex SWF calls
</script>



now i managed to fix it with getting rid of the if/else statements, but i'd rather have them to preserve www. or not www.

any suggestions?
User is online!Profile CardPM

Go to the top of the page


girasquid
post 28 Jul, 2008 - 01:12 PM
Post #2


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 1,210



Thanked 9 times

Dream Kudos: 650
My Contributions


Are you sure that you want to be testing loc2 for "//www", and not loc?

Also, why are you using split() at all? Couldn't you just use indexOf(), like so?

jscript

if(window.location.indexOf('http://www.') != -1) {
// www
} else {
// no-www
}
User is online!Profile CardPM

Go to the top of the page

BetaWar
post 28 Jul, 2008 - 01:14 PM
Post #3


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,635



Thanked 63 times

Dream Kudos: 1075
My Contributions


<edit>
Sorry, the code has some errors that I just realized so I am trying to ge tthem sorted out and I will edit it a gain.
</edit>

<edit2>
I keep recieving the error "Object (window.location) doesn't support this property or method." when using indexOf and split. I have also tried to do some other things but it doesn't work out. Still trying.
</edit2>

<edit3>
Got it to work:

CODE
<script>
//Flex SWF calls
function url(url){
  if(document.location.href.indexOf("http://www.") == 0){
    alert("Has www");
  }
  else{
    alert("doesn't have www");
  }
}
//end Flex SWF calls
</script>


Hope that helps.
</edit3>

See how that works out for you.

This post has been edited by BetaWar: 28 Jul, 2008 - 01:33 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/10/08 12:11PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month