JavaScript Help Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
2 posters

    JavaScript Help

    ThePhantomHourglass
    ThePhantomHourglass
    New Member


    Male Posts : 11
    Reputation : 1
    Language : English

    Solved JavaScript Help

    Post by ThePhantomHourglass March 23rd 2014, 3:07 am

    So I'm trying to make a script where anyone who is on a certain page on the site, it'll automatically be redirected to another page. For some reason, it's not working...

    I have it checked to show on all pages.

    Here's my code:
    Code:
    $(function(){
    $('a[href="http://aresiiocorpforums.forumotion.com/u3"]').not(function(){return $("img",this)[0]}).html('<script>window.location = "http://aresiiocorpforums.forumotion.com/profile?mode=viewprofile&u";</script>');
    });
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: JavaScript Help

    Post by Ange Tuteur March 23rd 2014, 3:16 am

    Hello ThePhantomHourglass,

    You can use the location object to change the pathname or entire URL.

    Pathname :
    Code:
    location.pathname = '/h1-';

    Result :
    User will be redirected to a custom HTML page

    Entire URL :
    Code:
    location.href = 'http://myforum.forumotion.com/h1-';

    Result :
    User will be redirected to an HTML page, or another page you chose

    You can also set a condition for the redirection :
    Code:
    if (location.pathname == '/forum') {
        location.pathname = '/h1-';
    }

    Result :
    If the users pathname is equal to /forum they will be redirected to an HTML page.
    ThePhantomHourglass
    ThePhantomHourglass
    New Member


    Male Posts : 11
    Reputation : 1
    Language : English

    Solved Re: JavaScript Help

    Post by ThePhantomHourglass March 23rd 2014, 3:39 am

    Ange Tuteur wrote:Hello ThePhantomHourglass,

    You can use the location object to change the pathname or entire URL.

    Pathname :
    Code:
    location.pathname = '/h1-';

    Result :
    User will be redirected to a custom HTML page

    Entire URL :
    Code:
    location.href = 'http://myforum.forumotion.com/h1-';

    Result :
    User will be redirected to an HTML page, or another page you chose

    You can also set a condition for the redirection :
    Code:
    if (location.pathname == '/forum') {
        location.pathname = '/h1-';
    }

    Result :
    If the users pathname is equal to /forum they will be redirected to an HTML page.
    I tried using the condition one. It doesn't seem to be working. Here's my code now:

    Code:
    $(function(){
    $('a[href="http://aresiiocorpforums.forumotion.com/u3"]').not(function(){return $("img",this)[0]}).html('<script>if (location.pathname == '/u3') {
        location.pathname = '/h2-';
    }";</script>');
    });
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: JavaScript Help

    Post by Ange Tuteur March 23rd 2014, 3:44 am

    Where do you want to place it ?

    If you want to place it on a profil you can do :
    Administration panel > modules > javascript codes management > create a new script

    Title : What you wish
    Placement : in all the pages
    Paste the code below and save :
    Code:
    if (location.pathname == '/u3') {
        location.pathname = '/h2-';
    }

    Once done the user should be redirected while on u3's profile page.
    ThePhantomHourglass
    ThePhantomHourglass
    New Member


    Male Posts : 11
    Reputation : 1
    Language : English

    Solved Re: JavaScript Help

    Post by ThePhantomHourglass March 23rd 2014, 3:51 am

    Ange Tuteur wrote:Where do you want to place it ?

    If you want to place it on a profil you can do :
    Administration panel > modules > javascript codes management > create a new script

    Title : What you wish
    Placement : in all the pages
    Paste the code below and save :
    Code:
    if (location.pathname == '/u3') {
        location.pathname = '/h2-';
    }

    Once done the user should be redirected while on u3's profile page.
    Ahh, thank you. I fixed it. I didn't know I didn't have to put it in a function.

    You can archive and mark as complete/solved now.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: JavaScript Help

    Post by Ange Tuteur March 23rd 2014, 3:53 am

    Welcome Smile

    Topic solved and archived