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 8 of 8
  1. #1
    som
    som is offline
    New Coder
    Join Date
    Dec 2009
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Easy problem (about a href links), immediate payment

    I need someone to link this:



    thiswebsite.com/12.html
    then someone clicks on a link, and the url would go to
    thiswebsite.com/12_1.html

    The link script has to subtract the ".html" from the original url, then add "_1.html" to the new url.

    I am pretty sure this is a simple script to make, I just do not have the time to google this and figure this out. I will pay $5 to anyone who fix this problem for me.
    you can post the solution here, with your paypal email so I can pay you,
    or email me the solution at hotgoat145@yahoo.com and tell me your paypal email so I can pay you.



    Im looking for a javascript code, because .htaccess does not work for me.
    it has to be in javascript,
    where it is like this
    <script language='JavaScript' type='text/javascript'>
    document.write('<a hr'+'ef="ht'+'tp://w'+'ww.mysite'+'.com/1.php">My Site</a>');
    </script>
    Only I have to be able to subtract .php from the URL, and add _2.html to the final URL




    Here is what I am talking about:
    Go to this website:
    http://tehcake.com/video/30rock/2x14%20-%20Copy.html

    Do you see where it says Backup Links: 1 2

    I need it to link to http://tehcake.com/video/30rock/2x14%20-%20Copy(2).html
    So it does (url of webpage [minus] file extension [plus] (2).html)
    it should be in javascript or something that can be written in the webpage.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,173
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Quote Originally Posted by som View Post
    thiswebsite.com/12.html
    then someone clicks on a link, and the url would go to
    thiswebsite.com/12_1.html

    The link script has to subtract the ".html" from the original url, then add "_1.html" to the new url.
    Code:
    var url = "thiswebsite.com/12.html"
    url = url.replace (/12/,"12_1")
    document.write(url);    //  thiswebsite.com/12_1.html
    Quizmaster: Which European country's name was literally intended to mean "The Way North"?
    Contestant: France.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Philip M, I don't think it's always 12 though. So it has to be the extension that gets replaced.

    Code:
    url=url.replace(/\.(php|html)/i, "_2.html");
    That's if I understand it correctly, and both html and php files need to be changed to _2.html.

    The link script has to subtract the ".html" from the original url, then add "_1.html" to the new url.
    Only I have to be able to subtract .php from the URL, and add _2.html to the final URL
    So it does (url of webpage [minus] file extension [plus] (2).html)
    Which one is it?
    Last edited by gusblake; 12-22-2009 at 05:01 PM. Reason: wrong brackets in regex

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,173
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Quote Originally Posted by gusblake View Post
    Philip M, I don't think it's always 12 though. So it has to be the extension that gets replaced.

    Code:
    url=url.replace(/\.[php|html]/i, "_2.html");
    That's if I understand it correctly, and both html and php files need to be changed to _2.html.
    Wrong sort of brackets:-

    url = url.replace(/\.(php|html)/i, "_2.html"); // [html] matches h or t or m or l

    But the guy does not make it at all clear. Could be:-

    url = url.replace(/\.(html)/i, "_1.html");
    url = url.replace(/\.(php)/i, "_2.html");

    The link script has to subtract the ".html" from the original url, then add "_1.html" to the new url.
    Only I have to be able to subtract .php from the URL, and add _2.html to the final URL
    Last edited by Philip M; 12-22-2009 at 03:50 PM.

  • #5
    som
    som is offline
    New Coder
    Join Date
    Dec 2009
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I am very close to the solution.
    Here is the javascript I have:
    <SCRIPT LANGUAGE="JavaScript">

    function hyperlink()
    {
    var url = (location.href)
    url = url.replace(/\.(html)/i, "_2.html")
    document.write(url);
    }
    // End -->
    </script>

    <a href="javascript:hyperlink()"><u>1</u></a>


    anyways, if you go to this site:
    http://tehcake.com/video/30rock/2x14%20-%20Copy.html

    and go to where it says backup links: 1 2
    and click on 1 ,
    it puts: http://tehcake.com/video/30rock/2x14%20-%20Copy_2.html , which is the correct url I want it to go to, only it is not written in the address bar, it is just written in the webpage.
    How would i make it so this:
    <SCRIPT LANGUAGE="JavaScript">

    function hyperlink()
    {
    var url = (location.href)
    url = url.replace(/\.(html)/i, "_2.html")
    document.write(url);
    }
    // End -->
    </script>

    actually goes to the webpage, and does not just write it in text?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,173
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    window.location = url;

    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.
    The <!-- and //--> comment (hiding) tags have not been necessary since IE3.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #7
    som
    som is offline
    New Coder
    Join Date
    Dec 2009
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Here is what I have:
    <script type = "text/javascript">

    function hyperlink()
    {

    var url = (location.href)
    url = url.replace(/\.(html)/i, "_2.html")
    document.write(url)
    window.location.href = url;
    }

    </script>

    This actually works, but it has 1 flaw:
    if you go to:
    http://tehcake.com/video/30rock/2x14 - Copy.html
    look to where it says Backup Links: 1 2
    and click on 1,
    it actually goes to
    http://tehcake.com/video/30rock/2x14 - Copy_2.html -
    like it is supposed to, but first it goes to a blank redirect webpage with the text in it: http://tehcake.com/video/30rock/2x14%20-%20Copy_2.html
    Is there any way for it to just go directly to:
    http://tehcake.com/video/30rock/2x14%20-%20Copy_2.html
    and not have the blank white redirect page in the way?
    Last edited by som; 12-22-2009 at 06:57 PM.

  • #8
    som
    som is offline
    New Coder
    Join Date
    Dec 2009
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    o sorry haha my mistake
    Actually, the javascript was supposed to be

    <script type = "text/javascript">

    function hyperlink()
    {

    var url = (location.href)
    url = url.replace(/\.(html)/i, "_2.html")
    window.location.href = url;
    }

    </script>

    Instead of:

    <script type = "text/javascript">

    function hyperlink()
    {

    var url = (location.href)
    url = url.replace(/\.(html)/i, "_2.html")
    document.write(url)
    window.location.href = url;
    }

    </script>


    I did not need the document.write(url) in the javascript.
    Ok thanks everyone


  •  

    Tags for this Thread

    Posting Permissions

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