Is there any way to pass data between links?

2

I want to make a page of redireccionando.html but I have several links in índex.html and I do not want to have to do redireccionando_link_1.html , redireccionando_link_2.html , etc.

Is it possible that I only have to do one redirecting page instead of one for each different link my page has?

That is, call redireccionando.html with a parameter that is the link that was clicked on.

Resolved:

At redireccionando.html I added the following script >

<script language="JavaScript" type="text/javascript">
  var url = location.href;
  var arr_url=url.split("?");
  var arr_var =arr_url[1].split("=");
  var pagina= arr_var[1];

  function redireccionar(){
    location.href=pagina
  } 

  setTimeout ("redireccionar()", 1000);
</script>

The page is called using the following format: http://www.yoyomero.com/redirecting.html?next=http://www.google.com

Where http://www.yoyomero.com/redirecting.html is the page

And ?next=http://www.google.com is where you want to go

    
asked by Jose Fabio 웃 22.12.2016 в 21:27
source

3 answers

3

You can do it from the JavaScript too

    var url= location.href;// Guardamos la  url actual
    var arr_url=url.split("?");// cortamos la url
    /*Esta función corta la url. Si la url es 
      "ejemplo.com/redirect?next=ejemplo.com" quedaría un arreglo
      ["ejemplo.com/redirect","next=ejemplo.com"] */

Notice that the sign "?" It is the delimiter. This function cuts a string where it finds the delimiter that we passed to it as a parameter. More information about this function. link .

     //Accedemos al segundo elemento del arreglo "arr_url"
     var arr_var =arr_url[1].split("=");
     //Solo si  tienes solo una variable 
     // si tienes más variables debes usar el delimitador "&" para cortar 
     var next_url= arr_var[1];

     location.href=next_url;
    
answered by 22.12.2016 / 23:48
source
2

The answer goes directly to how to do the redirection: It all depends on how you want to behave because there are 2 options:

1- That the re-address page is in the browser's history, which would make it difficult (not to say almost impossible) to back the navigation back using the "back" button of the browser, but there are cases where you want to that works like this so I leave you an example ...

In this case, use something like that in <head> of redireccionando.html :

<script>
  window.location.href = window.location.search.substring(1);
</script>

2- That the re-address page is not in the browser's history, which makes it work similar to Google when you click on a search, which first goes to an intermediate page that redirects you to the page you clicked on first place.

In this case, use something like that in <head> of redireccionando.html :

<script>
  window.location.replace(window.location.search.substring(1));
</script>

Wait ...

Both methods require that you invoke the page in this way

redireccionando.html?http%3A%2F%2Fotrositio.com%2Fotra_pagina.html

Where the address of the other site where you redirected is an encoded URL. There are several ways to encode the URL first. If you want you can use php in your index.html ... you could do it like this: (use an example of the repository you linked in the question)

<a href="redireccionando.html?<?=urlencode("https://www.facebook.com/yoyomerotienda/posts/1802148900025449")?>" title="D1 GHZ - Azul" target="_blank">
   <img alt="D1 GHZ Azul" src="http://yoyomero.com/eCommerceAssets/images/stuff/Loop/200x200.jpg">
</a>

Salu2

    
answered by 22.12.2016 в 22:06
1

You can add variables of type GET to your url to see where to redirect, there is even a common one that is called next , it is used in the following way:

http://yoursite.com/?next=redireccionando_link_1.html

Where ? tells the url that there will be a variable, next would be the name of the variable, and what is after the = is the value of the variable, note that as it can be called next you can also put redirect or whatever you want.

Now what is left is from your server that I do not know in what language you are programming it, recover the variable and decide where to redirect according to the value of said variable.

    
answered by 22.12.2016 в 21:34