<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Intel XDK iOS app - Javascript - How to get &amp;quot;Get&amp;quot; variable in iframe in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Intel-XDK-iOS-app-Javascript-How-to-get-quot-Get-quot-variable/m-p/1088513#M64421</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I added an iframe (&amp;lt;iframe src="page.html?var1=xxx") for example on my Intel Xdk iOs app.&lt;/P&gt;

&lt;P&gt;The page is well displayed, but GET variables don't work (work only in emulator, not after build)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Do you know how to get GET variables please ?&lt;/P&gt;

&lt;P&gt;I used this code&lt;/P&gt;

&lt;PRE class="brush:jscript;"&gt;    function $_GET() {
      // Get the Full href of the page e.g. &lt;A href="http://www.google.com/files/script.php?v=1.8.7&amp;amp;country=india" target="_blank"&gt;http://www.google.com/files/script.php?v=1.8.7&amp;amp;country=india&lt;/A&gt;
      var href = window.location.href;
	
      // Get the protocol e.g. http
      var protocol = window.location.protocol + "//";
	
      // Get the host name e.g. &lt;A href="https://community.intel.com/www.google.com" target="_blank"&gt;www.google.com&lt;/A&gt;
      var hostname = window.location.hostname;
	
      // Get the pathname e.g. /files/script.php
      var pathname = window.location.pathname;
	
      // Remove protocol part
      var queries = href.replace(protocol, '');
	
      // Remove host part
      queries = queries.replace(hostname, '');
	
      // Remove pathname part
      queries = queries.replace(pathname, '');
	
      // Presently, what is left in the variable queries is : ?v=1.8.7&amp;amp;country=india
	
      // Perform query functions if present
      if (queries != "" &amp;amp;&amp;amp; queries != "?") {
	
	    // Remove question mark ?
        queries = queries.slice(1);
	
        // Split all the different queries
        queries = queries.split("&amp;amp;");
		
        // Get the number of queries
        var length = queries.length;
		
        // Declare global variables to store keys and elements
        $_GET_Params = new Array();
        $_GET = {};
	
        // Perform functions per query
        for (var i  = 0; i &amp;lt; length; i++) {
			
          // Get the present query
          var key = queries&lt;I&gt;;
			
          // Split the query and the value
          key = key.split("=");
			
          // Assign value to the $_GET variable
          $_GET[key[0]] = [key[1]];
			
          // Assign value to the $_GET_Params variable
          $_GET_Params&lt;I&gt; = key[0];
        }
      }
    }

    // Execute the function
    $_GET();

&amp;lt;script&amp;gt;document.write($_GET['var1']);&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Aug 2016 22:37:00 GMT</pubDate>
    <dc:creator>Alexandre_T_</dc:creator>
    <dc:date>2016-08-07T22:37:00Z</dc:date>
    <item>
      <title>Intel XDK iOS app - Javascript - How to get "Get" variable in iframe</title>
      <link>https://community.intel.com/t5/Software-Archive/Intel-XDK-iOS-app-Javascript-How-to-get-quot-Get-quot-variable/m-p/1088513#M64421</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I added an iframe (&amp;lt;iframe src="page.html?var1=xxx") for example on my Intel Xdk iOs app.&lt;/P&gt;

&lt;P&gt;The page is well displayed, but GET variables don't work (work only in emulator, not after build)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Do you know how to get GET variables please ?&lt;/P&gt;

&lt;P&gt;I used this code&lt;/P&gt;

&lt;PRE class="brush:jscript;"&gt;    function $_GET() {
      // Get the Full href of the page e.g. &lt;A href="http://www.google.com/files/script.php?v=1.8.7&amp;amp;country=india" target="_blank"&gt;http://www.google.com/files/script.php?v=1.8.7&amp;amp;country=india&lt;/A&gt;
      var href = window.location.href;
	
      // Get the protocol e.g. http
      var protocol = window.location.protocol + "//";
	
      // Get the host name e.g. &lt;A href="https://community.intel.com/www.google.com" target="_blank"&gt;www.google.com&lt;/A&gt;
      var hostname = window.location.hostname;
	
      // Get the pathname e.g. /files/script.php
      var pathname = window.location.pathname;
	
      // Remove protocol part
      var queries = href.replace(protocol, '');
	
      // Remove host part
      queries = queries.replace(hostname, '');
	
      // Remove pathname part
      queries = queries.replace(pathname, '');
	
      // Presently, what is left in the variable queries is : ?v=1.8.7&amp;amp;country=india
	
      // Perform query functions if present
      if (queries != "" &amp;amp;&amp;amp; queries != "?") {
	
	    // Remove question mark ?
        queries = queries.slice(1);
	
        // Split all the different queries
        queries = queries.split("&amp;amp;");
		
        // Get the number of queries
        var length = queries.length;
		
        // Declare global variables to store keys and elements
        $_GET_Params = new Array();
        $_GET = {};
	
        // Perform functions per query
        for (var i  = 0; i &amp;lt; length; i++) {
			
          // Get the present query
          var key = queries&lt;I&gt;;
			
          // Split the query and the value
          key = key.split("=");
			
          // Assign value to the $_GET variable
          $_GET[key[0]] = [key[1]];
			
          // Assign value to the $_GET_Params variable
          $_GET_Params&lt;I&gt; = key[0];
        }
      }
    }

    // Execute the function
    $_GET();

&amp;lt;script&amp;gt;document.write($_GET['var1']);&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Aug 2016 22:37:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Intel-XDK-iOS-app-Javascript-How-to-get-quot-Get-quot-variable/m-p/1088513#M64421</guid>
      <dc:creator>Alexandre_T_</dc:creator>
      <dc:date>2016-08-07T22:37:00Z</dc:date>
    </item>
    <item>
      <title>For starters, where is this</title>
      <link>https://community.intel.com/t5/Software-Archive/Intel-XDK-iOS-app-Javascript-How-to-get-quot-Get-quot-variable/m-p/1088514#M64422</link>
      <description>&lt;P&gt;For starters, where is this script running? It should run from the page that is included _into_ the iframe, not its parent.&lt;/P&gt;

&lt;P&gt;That's a lot work to get the query. &amp;nbsp;Try this:&lt;/P&gt;

&lt;PRE class="brush:jscript;"&gt;function getQuery(name){
   var queryString = document.location.search; //?v=1.8.7&amp;amp;country=india
   queryString = queryString.substr(1); //drop ?
   var pairStrings = queryString.split("&amp;amp;"); //["v=1.8.7", "country=india"]
   var pairs = {};
   pairStrings.forEach(function(str){ 
     var pair = str.split("=");  // ["v", "1.8.7"]
     pairs[pair[0]] = pair[1];  // {v:"1.8.7"}
   });
   return pairs[name]; 
}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 20:39:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Intel-XDK-iOS-app-Javascript-How-to-get-quot-Get-quot-variable/m-p/1088514#M64422</guid>
      <dc:creator>Chris_P_Intel</dc:creator>
      <dc:date>2016-08-08T20:39:54Z</dc:date>
    </item>
  </channel>
</rss>

