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 Sun 23 Mar 2014 - 3:07

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 Sun 23 Mar 2014 - 3:16

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 : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: JavaScript Help

Post by ThePhantomHourglass Sun 23 Mar 2014 - 3:39

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 Sun 23 Mar 2014 - 3:44

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 : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: JavaScript Help

Post by ThePhantomHourglass Sun 23 Mar 2014 - 3:51

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 Sun 23 Mar 2014 - 3:53

Welcome Smile

Topic solved and archived
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
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