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.

redirecting script problem

3 posters

Go down

Solved redirecting script problem

Post by neos July 18th 2016, 11:53 am

ehm
Hi all
i was using a code to redirect post links in a good way actually
like
u'll be redirected to the link in 5 secs and here's the code
and here's the java code for it
Code:
$(function () {
  $(".post-entry a").not("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.png'],a[href$='.gif'],a[href$='.bmp'],a[href^='/'],a[href^='" + location.origin + "']").click(function (a) {
      a.preventDefault();
      a = location.href;
      var b = this.href;
      z = "/redirect/?url=" + encodeURIComponent(b);
      window.history && history.pushState ? history.pushState({}, "Redirecting...", z) : location.hash = z;
      var d, c = 5;
      $("#main-content").html('<div id="redirects"><h3>Redirecting...</h3><p class="redirectMess">You are preparing to leave <strong>' +
        document.title + '</strong>and move to the path: <strong><a href="' + b + '" rel="nofollow">' + b + '</a></strong>within <strong><span class="delayTime">' + c + '</span></strong>more seconds ... You want to make sure that this path is not?</p><div class="redirectFooter"><ul class="redirectButtons"><li><a class="cancel" href="' + a + '">back</a></li><li><a href="' + b + '" class="redirectSkip forward" rel="nofollow">continue (<span class="delayTime">' +
        c + "</span>)</a></li></ul></div></div>");
      d = setInterval(function () {
        var a = c--;
        0 > a ? window.location = b : $(".delayTime").text(a)
      }, 1E3);
      $(".redirectButtons a").click(function () {
        clearInterval(d)
      })
  })
});


so the problem is
the code opens the post link in the same page
i was wondering if there's anyways to make it opens in a new window ?



Last edited by neos on July 19th 2016, 11:00 am; edited 1 time in total
neos
neos
Forumember

Posts : 36
Reputation : 1
Language : Englsh
Location : Egypt

http://the-elite.forum-pro.net/

Back to top Go down

Solved Re: redirecting script problem

Post by An July 18th 2016, 12:09 pm

Hi Mr. Green

Try replacing
Code:
window.location = b : $(".delayTime").text(a)
with
Code:
window.open(b : $(".delayTime").text(a));
. If that doesn't work, you can make a redirect anchor with target="_blank" and force click it with javascript. Here is an example:
Code:
var a = $('<a href="http://help.forumotion.com/u94304" target="_blank" />')[0];
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
An
An
Forumember

Posts : 44
Reputation : 24
Language : English

https://help.forumotion.com

Back to top Go down

Solved Re: redirecting script problem

Post by neos July 18th 2016, 12:25 pm

awrighty
the first method did opened it in a new window
but the direction thingy didn't appear actually
here's the things
this code suppose to have this redirection page if someone clicked on the external links
redirecting script problem  Red10

and it's opening in the same page
and when i tried ur method #1
it opened in a new window but that redirecting page didn't appear
so about your method #2
i actually didn't frankly get it
0.0
can u please clarify it a little ?
thanks in advance
neos
neos
Forumember

Posts : 36
Reputation : 1
Language : Englsh
Location : Egypt

http://the-elite.forum-pro.net/

Back to top Go down

Solved Re: redirecting script problem

Post by An July 18th 2016, 12:44 pm

oooo I'm sorry, I misread your script! beu It should have been
Code:
0 > a ? window.open(b) : $(".delayTime").text(a)
.

The second method creates a link and clicks it. It works about the same as window.open.
An
An
Forumember

Posts : 44
Reputation : 24
Language : English

https://help.forumotion.com

Back to top Go down

Solved Re: redirecting script problem

Post by neos July 18th 2016, 12:53 pm

tried it
still opens in the same window o.o
neos
neos
Forumember

Posts : 36
Reputation : 1
Language : Englsh
Location : Egypt

http://the-elite.forum-pro.net/

Back to top Go down

Solved Re: redirecting script problem

Post by An July 18th 2016, 3:56 pm

How about this?
Code:
$(function () {
  $(".post-entry a").not("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.png'],a[href$='.gif'],a[href$='.bmp'],a[href^='/'],a[href^='" + location.origin + "']").click(function (a) {
      a.preventDefault();
      a = location.href;
      var b = this.href;
      z = "/redirect/?url=" + encodeURIComponent(b);
      window.history && history.pushState ? history.pushState({}, "Redirecting...", z) : location.hash = z;
      var d, c = 5;
      $("#main-content").html('<div id="redirects"><h3>Redirecting...</h3><p class="redirectMess">You are preparing to leave <strong>' +
        document.title + '</strong>and move to the path: <strong><a href="' + b + '" rel="nofollow">' + b + '</a></strong>within <strong><span class="delayTime">' + c + '</span></strong>more seconds ... You want to make sure that this path is not?</p><div class="redirectFooter"><ul class="redirectButtons"><li><a class="cancel" href="' + a + '">back</a></li><li><a href="' + b + '" class="redirectSkip forward" rel="nofollow" target="_blank">continue (<span class="delayTime">' +
        c + "</span>)</a></li></ul></div></div>");
      d = setInterval(function () {
        var a = c--;
        0 > a ? $('.redirectSkip')[0].click() : $(".delayTime").text(a)
      }, 1E3);
      $(".redirectButtons a").click(function () {
        clearInterval(d)
      })
  })
});
I changed it so that it clicks the skip button instead, since it goes to the same link. (I just added target="_blank" so it opens a new tab)
An
An
Forumember

Posts : 44
Reputation : 24
Language : English

https://help.forumotion.com

Back to top Go down

Solved Re: redirecting script problem

Post by neos July 18th 2016, 9:33 pm

i've tried this too bro
but still opens in the same page
Evil or Very Mad Evil or Very Mad
neos
neos
Forumember

Posts : 36
Reputation : 1
Language : Englsh
Location : Egypt

http://the-elite.forum-pro.net/

Back to top Go down

Solved Re: redirecting script problem

Post by An July 18th 2016, 11:55 pm

It opens in a new tab for me but you have to allow popups.. I can't think of anything else. These are all the things that open in new windows that I can find:

window.open - https://developer.mozilla.org/en-US/docs/Web/API/Window/open
target (attr for anchor) - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target

For what you are doing, I think it would probably be best if the user chose to continue or go back instead of being redirected automatically.
An
An
Forumember

Posts : 44
Reputation : 24
Language : English

https://help.forumotion.com

Back to top Go down

Solved Re: redirecting script problem

Post by neos July 19th 2016, 11:00 am

okay bro
thanks alot for helping out
^_^
i decided to abandon the whole code
thanks again
neos
neos
Forumember

Posts : 36
Reputation : 1
Language : Englsh
Location : Egypt

http://the-elite.forum-pro.net/

Back to top Go down

Solved Re: redirecting script problem

Post by Ape July 19th 2016, 12:31 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


redirecting script problem  Left1212redirecting script problem  Center11redirecting script problem  Right112
redirecting script problem  Ape_b110
redirecting script problem  Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19209
Reputation : 1998
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top

- Similar topics

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