<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.caballero.co/index.php?action=history&amp;feed=atom&amp;title=Javascript%2C_Variables_en_URL_como_Anchors</id>
	<title>Javascript, Variables en URL como Anchors - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.caballero.co/index.php?action=history&amp;feed=atom&amp;title=Javascript%2C_Variables_en_URL_como_Anchors"/>
	<link rel="alternate" type="text/html" href="http://wiki.caballero.co/index.php?title=Javascript,_Variables_en_URL_como_Anchors&amp;action=history"/>
	<updated>2026-04-21T19:57:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>http://wiki.caballero.co/index.php?title=Javascript,_Variables_en_URL_como_Anchors&amp;diff=356&amp;oldid=prev</id>
		<title>Felipe: Felipe moved page Variables en URL como Anchors to Javascript, Variables en URL como Anchors</title>
		<link rel="alternate" type="text/html" href="http://wiki.caballero.co/index.php?title=Javascript,_Variables_en_URL_como_Anchors&amp;diff=356&amp;oldid=prev"/>
		<updated>2014-07-21T22:59:35Z</updated>

		<summary type="html">&lt;p&gt;Felipe moved page &lt;a href=&quot;/index.php/Variables_en_URL_como_Anchors&quot; class=&quot;mw-redirect&quot; title=&quot;Variables en URL como Anchors&quot;&gt;Variables en URL como Anchors&lt;/a&gt; to &lt;a href=&quot;/index.php/Javascript,_Variables_en_URL_como_Anchors&quot; title=&quot;Javascript, Variables en URL como Anchors&quot;&gt;Javascript, Variables en URL como Anchors&lt;/a&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:59, 21 July 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Felipe</name></author>
	</entry>
	<entry>
		<id>http://wiki.caballero.co/index.php?title=Javascript,_Variables_en_URL_como_Anchors&amp;diff=181&amp;oldid=prev</id>
		<title>Felipe: Created page with &quot;Hay algunos sitios que utilizan frames, iframes o partes variables adentro de la misma página. Esto es útil a la hora de programar pero puede tener un problema de usabilidad...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.caballero.co/index.php?title=Javascript,_Variables_en_URL_como_Anchors&amp;diff=181&amp;oldid=prev"/>
		<updated>2013-11-15T13:49:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Hay algunos sitios que utilizan frames, iframes o partes variables adentro de la misma página. Esto es útil a la hora de programar pero puede tener un problema de usabilidad...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Hay algunos sitios que utilizan frames, iframes o partes variables adentro de la misma página. Esto es útil a la hora de programar pero puede tener un problema de usabilidad para el lector de la página, si quieres mandar el link exacto a un amigo o guardar el link en favoritos por ejemplo, se guarda el URL de la página sin las modificaciones internas o el iframe correcto.&lt;br /&gt;
&lt;br /&gt;
Para solucionar esto, se puede usar un truco, usar la parte de los anchors del URL para guardar variables, todo con javascript.&lt;br /&gt;
&lt;br /&gt;
A continuación hay un ejemplo de una librería básica para llevar a cabo esta idea. Primero el uso de la librería y luego el código.&lt;br /&gt;
&lt;br /&gt;
==Uso==&lt;br /&gt;
Guardar el código en un archivo llamado &amp;lt;code&amp;gt;params.js&amp;lt;/code&amp;gt;, en el html cargar el archivo y usar las siguientes funciones.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
params.setParam(paramName,paramValue) // para setear un parametro, lo guarda en la URL&lt;br /&gt;
params.getParam(paramName)	      // para obtener lo que contiene el parametro, lo obtiene de la URL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Código==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
//*****************************************************************&lt;br /&gt;
//	By Flat Estrategia Digital &amp;lt;http://www.flat.cl/&amp;gt;&lt;br /&gt;
//	&amp;lt;contacto@flat.cl&amp;gt;&lt;br /&gt;
//	Created By: Felipe Caballero, Feb 19, 2010&lt;br /&gt;
//		Description:&lt;br /&gt;
//	This object is used to set/retrieve variables from the&lt;br /&gt;
//	anchor part of the URL&lt;br /&gt;
//*****************************************************************&lt;br /&gt;
var params = {&lt;br /&gt;
	nameList: null, // List of Params names&lt;br /&gt;
	valueList: null, // List of Params values&lt;br /&gt;
	anchs: null, // Initialized with the values in hash part of URL&lt;br /&gt;
	// Next function sets a new parameter in the hash part or URL&lt;br /&gt;
	setParam: function(param, val) {&lt;br /&gt;
		this.retrieveParams();&lt;br /&gt;
		if (this.anchs == &amp;quot;&amp;quot;)&lt;br /&gt;
		{&lt;br /&gt;
			location.hash = param + &amp;quot;/&amp;quot; + val;&lt;br /&gt;
			return;&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			var urlParams = &amp;quot;&amp;quot;, createNewParam = true;&lt;br /&gt;
			for (i = 0; i &amp;lt; this.nameList.length; i++)&lt;br /&gt;
			{&lt;br /&gt;
				if (this.nameList[i] == param)&lt;br /&gt;
				{&lt;br /&gt;
					this.valueList[i] = val;&lt;br /&gt;
					createNewParam = false;&lt;br /&gt;
					break;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			if (createNewParam)&lt;br /&gt;
			{&lt;br /&gt;
				var nameTemp, valueTemp;&lt;br /&gt;
				nameTemp = new Array(this.nameList.length + 1);&lt;br /&gt;
				valueTemp = new Array(this.nameList.length + 1);&lt;br /&gt;
				for (i = 0; i &amp;lt; this.nameList.length; i++)&lt;br /&gt;
				{&lt;br /&gt;
					nameTemp[i] = this.nameList[i];&lt;br /&gt;
					valueTemp[i] = this.valueList[i];&lt;br /&gt;
				}&lt;br /&gt;
				nameTemp[nameTemp.length - 1] = param;&lt;br /&gt;
				valueTemp[valueTemp.length - 1] = val;&lt;br /&gt;
				this.nameList = nameTemp;&lt;br /&gt;
				this.valueList = valueTemp;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			for (i = 0; i &amp;lt; this.nameList.length; i++)&lt;br /&gt;
			{&lt;br /&gt;
				if (i == 0)&lt;br /&gt;
					urlParams += this.nameList[i] + &amp;quot;/&amp;quot; + this.valueList[i];&lt;br /&gt;
				else&lt;br /&gt;
					urlParams += &amp;quot;&amp;amp;&amp;quot; + this.nameList[i] + &amp;quot;/&amp;quot; + this.valueList[i];&lt;br /&gt;
			}&lt;br /&gt;
			location.hash = urlParams;&lt;br /&gt;
		}&lt;br /&gt;
	},&lt;br /&gt;
	// Next function gets a new parameter in the hash part or URL&lt;br /&gt;
	getParam: function(param) {&lt;br /&gt;
		this.retrieveParams();&lt;br /&gt;
		for (i = 0; i &amp;lt; this.nameList.length; i++)&lt;br /&gt;
		{&lt;br /&gt;
			if (this.nameList[i] == param)&lt;br /&gt;
			{&lt;br /&gt;
				return this.valueList[i];&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return null;&lt;br /&gt;
	},&lt;br /&gt;
	// Next function is called before other functions&lt;br /&gt;
	retrieveParams: function() {&lt;br /&gt;
		this.nameList = null;&lt;br /&gt;
		this.valueList = null;&lt;br /&gt;
		this.anchs = location.hash;&lt;br /&gt;
		if (location.href) {&lt;br /&gt;
			var paramArray = this.anchs.substr(1).split(&amp;#039;&amp;amp;&amp;#039;);&lt;br /&gt;
			this.nameList = new Array(paramArray.length);&lt;br /&gt;
			this.valueList = new Array(paramArray.length);&lt;br /&gt;
			for (i = 0; i &amp;lt; paramArray.length; i++)&lt;br /&gt;
			{&lt;br /&gt;
				this.nameList[i] = paramArray[i].split(&amp;#039;/&amp;#039;)[0];&lt;br /&gt;
				this.valueList[i] = paramArray[i].split(&amp;#039;/&amp;#039;)[1];&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Felipe</name></author>
	</entry>
</feed>