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.

JavaScript Help

2 posters

Go down

Solved JavaScript Help

Post by ThePhantomHourglass March 23rd 2014, 2: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
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 March 23rd 2014, 2: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
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: JavaScript Help

Post by ThePhantomHourglass March 23rd 2014, 2: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
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 March 23rd 2014, 2: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
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: JavaScript Help

Post by ThePhantomHourglass March 23rd 2014, 2: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
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 March 23rd 2014, 2:53 am

Welcome Smile

Topic solved and archived
Ange Tuteur
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

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