The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

JavaScript Help

View previous topic View next topic Go down

Solved JavaScript Help

Post by ThePhantomHourglass on 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>');
});

ThePhantomHourglass
New Member

Male Posts : 11
Reputation : 1
Language : English

http://aresiiocorpforums.forumotion.com/

Back to top Go down

Solved Re: JavaScript Help

Post by Ange Tuteur on 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.

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2684
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: JavaScript Help

Post by ThePhantomHourglass on 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>');
});

ThePhantomHourglass
New Member

Male Posts : 11
Reputation : 1
Language : English

http://aresiiocorpforums.forumotion.com/

Back to top Go down

Solved Re: JavaScript Help

Post by Ange Tuteur on 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.

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2684
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: JavaScript Help

Post by ThePhantomHourglass on 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.

ThePhantomHourglass
New Member

Male Posts : 11
Reputation : 1
Language : English

http://aresiiocorpforums.forumotion.com/

Back to top Go down

Solved Re: JavaScript Help

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

Welcome Smile

Topic solved and archived

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2684
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum