[HELP] Can you do this small work for free? it would take a min only !

Discussion in 'JavaScript' started by dipenrique, Jul 2, 2010.

  1. #1
    Please help me !

    I need a javascript !

    such that it can be used to redirect according to the web url !


    suppose if someone asks for

    oldsite.com/2009/page.html

    i could redirect it to newsite.com/2009/page.html


    i know its too simple ! but i am unable to make that function !


    ir will use location.href
    and string functions like search and replace !

    but i have very less knowledge of js,if someone can help me it would be great !
    else i would have to learn to do it on my own !
     
    Last edited: Jul 2, 2010
    dipenrique, Jul 2, 2010 IP
  2. c_programmer

    c_programmer Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It took you far longer to type that than it would have to learn it. Do the following
    1. Go to Google
    2. Type in "javascript redirect"
    3. Search
    4. Go to the first link

    That link will have exactly what you need.

    Most simple issues can be solved using that method.
     
    c_programmer, Jul 2, 2010 IP
  3. dipenrique

    dipenrique Peon

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    do i look that dumb? i did everything ! googled enough but didnt get what i was looking for thats why i posted here !

    i need redirection based on some conditions...after some string replacement
     
    dipenrique, Jul 2, 2010 IP
  4. c_programmer

    c_programmer Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You used the line: "else i would have to learn to do it on my own !", so I had reasonable base to assume you did zero work on your part. Although I did misunderstand your post.

    You would be better off using mod_rewrite (or IIS rewrite if windows) to do a 403 redirect, but if JS is a must this should work:
    
    var currentSite=window.location; //Lets say it is http://oldsite.com/dir/file.php
    var currentSiteName="oldsite.com";
    var newSiteName="newsite.com" 
    window.location = currentSite.replace(currentSiteName,newSiteName);
    
    
    Code (markup):
    This just takes the current site URL and replaces the domain (specified by you) with another domain (also specified by you).
     
    c_programmer, Jul 2, 2010 IP
  5. dipenrique

    dipenrique Peon

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry maybe i was looking rude ! sorry didnt mean to hurt !

    i said that because i meant i would have to learn javascipt from w3schools ! because i need it !
    acutally i tried this code only ! the one you wrote ! but i want it to work on blogger ! it isnt working their ! i tried posting this code in the html/javascript widget ! it reads the url also stores in temporary variable ! but the replace function doesnt work their ! i dont know why !
     
    dipenrique, Jul 2, 2010 IP
  6. c_programmer

    c_programmer Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That code should work (I did not test it though), perhaps you are being restricted on blogger. I know nothing about blogger so I can't help you with that.
     
    c_programmer, Jul 2, 2010 IP
  7. greenlizard

    greenlizard Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Can't you just do the following?

    
    <script type="text/javascript">
    <!--
    window.location = "http://www.newpage.com/"
    //-->
    </script>
    
    Code (markup):

    I just re-read the problem... the above won't work in your case. It's tough to do that on a blogger site when you don't have access to the files or .htaccess or anything. But, you could simply redirect the whole site by putting the above code in your header. Even add a delay that says, "This site has moved, you'll be redirected soon". Yes, they won't be redirected to the exact article, but, at least they'll get redirected to the new site.
     
    Last edited: Jul 3, 2010
    greenlizard, Jul 3, 2010 IP
  8. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #8
    Hmm, try meta refresh:
    <script type="text/javascript">
    <!--
    var lol = "<meta http-equiv=\"refresh\" content=\"0;url=http://google.com\">";
    document.write(lol);
    //-->
    </script>
    Code (markup):
     
    Rainulf, Jul 3, 2010 IP
  9. dipenrique

    dipenrique Peon

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    you people are write ! these coding would be enough to just redirect ! but i dont want that, i want to redirect depending on the url in the address bar ! and this should work on blogger blog !
     
    dipenrique, Jul 4, 2010 IP
  10. c_programmer

    c_programmer Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Blogger may not allow you to do that, have you tries running other types of javascript on Blogger?.

    ps. Why do you separate everything with an "!"?
     
    c_programmer, Jul 4, 2010 IP