1
With this php code, we pass variables to url manually.
if (isset($_GET['layout'])) {
$layout = $_GET['layout'];
} else {
$layout = '1';
}
With this other, in javascript, authored by @dvd apply the variable passed in the URL to all links on the page.
var url_ = location.href,
param = url_.substring(url_.lastIndexOf("/"), url_.length),
params = ['layout','teste']; // insira aqui os nomes das variáveis
for(var y=0; y<params.length; y++){
if(param.indexOf(params[y]) != -1){
var var_ = url_.substring(url_.indexOf(params[y])+params[y].length+1,url_.length).match(/^(\d|\w){1,}/)[0],
a_ = document.body.querySelectorAll("a");
for(var x=0; x<a_.length; x++){
a_[x].href += (a_[x].href.indexOf("?") == -1 ? "?" : "&")+params[y]+"="+var_;
}
}
}
All this works a lot. What I would like now is. Pass the variables to URL, through a select box.
<select id="layout" name="layout">
<option value="/?layout=1" selected="selected">Layout 1</option>
<option value="/?layout=2">Layout 2</option>
<option value="/?layout=3">Layout 3</option>
<option value="/?layout=4">Layout 4</option>
</select>
Remembering that you can have more than one select. One to layout, another to sidebar, and that the selection of one should be maintained when another is selected and the page is updated.
You want to do the same thing, change the page links, only now using selects?
– Sam
@dvd exactly.
– John Quimera
@dvd, yes, that’s right.
– John Quimera
But then it got confused for me. What is the relation of the variable in the page URL with the selects box? For example, let’s say the page URL is: site.com.br/? layout=2.... what is the relationship with select box?
– Sam
@dvd I call the variable by typing it in the right browser input?
?layout=2
?layout=3
etc... I want to call them through select, and not have to type them in the browser input.– John Quimera
@dvd I believe you should have a refresh on the page when select is selected right? and no problem, I think your current javascript solution should apply automatically, since the page has updated and it will get the url.
– John Quimera
I understood it like this: it checks if the URL has one of the variables, selects automatically in the respective select and inserts in the links of the page... that’s it?
– Sam
@dvd is exactly that.
– John Quimera
Let’s go continue this discussion in chat.
– Sam