Attention:

Support Rules and Guidelines
Before you post your support topic, please remember to:
  • Read the support forum rules.
  • Check the wiki and use search to see if your problem can be answered there first.
  • Link your board please, and make sure that the problem on your board is visible to guests or provide a test account.
  • Do not post Board Wrappers and CSS unless requested. With a board link, this is not necessary.
  • Be as descriptive as you can and use as many details as possible when describing your problem.
  • Please briefly mark any links to forums that may not be work-safe.
This will help ensure your support issue will be attended to in a quick and efficient manner.

  Add ReplyNew TopicNew Poll

 Redirect / Javascript Help
#
Hey there! I am currently using the following code:

<script>document.location="/index.php?showuser=<!-- |id| -->?s=&skinid=5";</script>

Which, unfortunately, for my uses means it get stuck in an endless loop.

Is there a way to have a code that will detect if the page is already:
/index.php?showuser=<!-- |id| -->?s=&skinid=5

And if not, reroute them to:
/index.php?showuser=<!-- |id| -->?s=&skinid=5

Thanks for any help in this matter, even if to tell me this is not an option.

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
I think you could use <!-- |skin_id| --> in a conditional, rather than regexing the URL.

CODE
if(<!-- |skin_id| --> != 5) {document.location='/index.php?showuser=<!-- |id| -->?s=&skinid=5'}
PM
#
I'm sorry Dusty you are an absolute genius when it comes to this stuff, but I have no idea what most of those words meant. I'm sorry, I'm quite thick when it comes to Javascript, I really need to take a course or something. Here's what I tried adding to my page:

CODE
<script>if(<!-- |skin_id| --> != 5) {document.location='/index.php?showuser=<!-- |id| -->?s=&skinid=5'}</script>


And it didn't really do what I was looking for. Perhaps if I explain my weird set up better.

I'm using this on a profile, but because of some weird stuff I'm doing I only want people to look at their own profiles. That's why I added:

<script>document.location="/index.php?showuser=<!-- |id| -->?s=&skinid=5";</script>

Which works great - if they click on my profile, they're redirected to the profile of the account they're currently logged into which is great - step one completed.

However, it's too great, because once they're looking at their own profile, the code continues to try and redirect them to their own profile in an endless loop - so what I'm looking for is a redirect code that can detect when it's already done it's job (redirected them to their own profile) and stops the loop, if that makes sense?

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
I'm okay at best ;b

Whoops! I thought you were aiming for forcing a skin selection, not to a user. Since I can't use wrapper variables in the Scratchpad, this is untested but shooould work?

CODE
var uP = window.location.search.substring(1).split("&");
for (var i=0;i<uP.length;i++){
      var kV = uP[i].split('=');
      if((kV[0] = 'showuser') && (kV[1] != '<!-- |id| -->')) {
             document.location='/index.php?showuser=<!-- |id| -->?s=&skinid=5'
      }
}
PM
#
Sorry, Dusty, I didn't explain it very clearly at first at all.

Looks like this is caught in an endless loop too, though I might have messed up somehow.

I don't blame you if you'd like to give up, but if you're still game, I don't think it'll work until you log in.

This post has been edited by owl: Jul 8 2018, 10:09 PM

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
Hmm.

What's going on with the URL? The reason it's failing is this lil bolded tid bit:

kalopsion.jcink.net/index.php?showuser=1?s=&skinid=5

Is there something that's appending th --------


OHHHHH intermission literally just saw it. My bad, I made a typo in my script
CODE
var uP = window.location.search.substring(1).split("&");
for (var i=0;i<uP.length;i++){
     var kV = uP[i].split('=');
     if((kV[0] = 'showuser') && (kV[1] != '<!-- |id| -->')) {
            document.location='/index.php?showuser=<!-- |id| -->&skinid=5'
     }
}


try that

This post has been edited by Dusty: Jul 7 2018, 11:05 PM
PM
#
I left the new coding intact. Looks like it's still looping, Dusty - is there a different way I should be parsing the URL to make this work better?

Thank you so much with your time in this; sorry I've picked up a weird and difficult set up for this.

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
oh my goodness I am a moron right now, what am I thinking. document.location is a read-only object, sorry. You need location.href instead

CODE
var uP = window.location.search.substring(1).split("&");
for (var i=0;i<uP.length;i++){
    var kV = uP[i].split('=');
    if((kV[0] = 'showuser') && (kV[1] != '3')) {
           location.href='/index.php?showuser=<!-- |id| -->&skinid=5'
    }
}
PM
#
You are the opposite of a moron, Dusty for real. Trust me, I've been in a million support threads just like this - usually cause someone is trying to pull of something unduly complicated way above their skill set - in this instance, me. Oops.

Looks like it's still looping though. Please do let me know if this is something that just isn't doable - due to my completely lack of Javascript knowledge, I have no idea how much I'm asking for here, and if it's too much I can totally accept that, and appreciate your attempts thusfar.

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
Curious! This is totally doable, just not sure entirely sure why it's causing a loop.

Try this:

CODE
if ('<!-- |input_act| -->' == 'Profile') {
   var uP = window.location.search.substring(1).split("&");
   for (var i = 0; i < uP.length; i++) {
       var kV = uP[i].split('=');
       console.log(kV[0])
       if ((kV[0] == 'showuser') && (kV[1] != '<!-- |id| -->')) {
           location.href = '/index.php?showuser=<!-- |id| -->&skinid=5'
       }
   }
}


If it works fine, feel free to strip the console.log statements out.

This post has been edited by Dusty: Jul 8 2018, 12:24 AM
PM
#
So it stopped the looping, but it isn't doing the re-directing now. I do simply have it pasted into the top of the Profile template, though, because that's where I had the initial script - let me know if I should move it somewhere else, cause I'm clueless.

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
Try putting it in your main wrappers - the first conditional will prevent it from running anywhere except a profile. None of the wrapper variables are resolving appropriately ('<!-- |input_act| -->' isn't being changed, and the id variable is returning to the ID of the profile you're viewing)
PM
#
Oh my gosh, I'm so thick. Sorry I didn't think to mention where I was putting it, earlier - makes a lot of sense that it was getting the wrong ID considering where I had it. It's working perfectly now, though! Thank you so much, Dusty!

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
#
No biggy! At least it works finally, whew.

Also, as always: your site designs are so cool
PM
#
You're so sweet, thank you so much! They wouldn't be nearly as cool without your help. ^^

signature
Kindly do not contact me on Discord or PM me for support.

user posted image
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
Share this topic:
« Next Oldest | General Support | Next Newest »

Options Add ReplyNew TopicNew Poll