Like SystemiConnectFri 15 Oct 2021, 04:50
Auto Save MessagesLGforumFri 26 Feb 2021, 13:31
New tutorial questionTheCrowMon 15 Feb 2021, 08:12
Support iOS Emojis (and other platforms)LGforumSun 14 Feb 2021, 01:25
LGforum (2806)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Mr.Easybb (1587)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Bloodbath (745)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Rukiafan (533)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Dom (513)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
puppycheese (446)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
pedro (330)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Neymar (301)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Hitsu (281)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 
Flora (275)
Replace an URL with URL that equals to it Vote_lcapReplace an URL with URL that equals to it Voting_barReplace an URL with URL that equals to it Vote_rcap 


Replace an URL with URL that equals to it

HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Mon 01 Jun 2015, 01:54
So, I would like to know how to replace an URL with another URL that equals to it.
Example like this:

Code:
var links = {
insane:'crazy',
test:'testing'
};

So the script would replace the URL. Like, if we typed [ic]urltotheforum.forumotion.com/insane[/ic] then the script would replace the URL into [ic]urltotheforum.forumotion.com/crazy[/ic].

Thank yu.
BloodbathBloodbath
Status : No status yet...

Posts : 745
Join date : 2013-05-31
Age : 28
Mon 01 Jun 2015, 11:07
It's not possible to do URL rewriting (like you can on an Apache server using .htaccess). There are ways to load a new page through JavaScript, but you can't link to an invalid page or the JS won't work.
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Mon 01 Jun 2015, 13:11
So is there another way to write it? ANY other way.
BloodbathBloodbath
Status : No status yet...

Posts : 745
Join date : 2013-05-31
Age : 28
Mon 01 Jun 2015, 13:44
Basically, if you want, for example, "/t41235-" to redirect to "/t1234-", then yes, that's possible, but I am afraid that what you have in mind isn't.
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Mon 01 Jun 2015, 21:09
Oh, yes, that's what I need. Could you give me some instruction? Thank you very much. Very Happy
DomDom
Status : No status yet...

Posts : 513
Join date : 2011-12-24
Location : USA
Mon 01 Jun 2015, 21:30
Sure, you can definitely do that. But it has to be a real URL already on the forum.

Code:
var redirects = {
"t1234": "t2314-",
"t123": "t1-"
};

for (var to in redirects) {
    if (window.location.pathname.indexOf(to) === 1) window.location.pathname = redirects[to];
}

It should work. I haven't worked with JavaScript for some time, but it should be right.
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Tue 02 Jun 2015, 13:12
Right, thank you! I'll test it in a minute.
LGforumLGforum
Status : Working to restore AWC!

Posts : 2806
Join date : 2011-10-05
Age : 30
Location : UK
Tue 09 Jun 2015, 15:25
You can put change the URL of an address without server side re-writing but you can change where a link on the page sends you:
(Ugly JQuery example to show what I mean)
Code:
[panda=js]$('a[href="/crazy").click(function(e){ e.preventDefault(); window.location = 'new location' });

If this is okay for you I can write something more complete.
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Sun 14 Jun 2015, 23:24
Ah, right. I've forgotten that I can write something easy like that lol, JK. But of course, it just might work if the link was clicked, ex like an URL bbcode. So, if that's not a problem for you: can you write more complete code? Thank you so much. ^^
Sponsored content