- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I added an iframe (<iframe src="page.html?var1=xxx") for example on my Intel Xdk iOs app.
The page is well displayed, but GET variables don't work (work only in emulator, not after build)
Do you know how to get GET variables please ?
I used this code
function $_GET() {
// Get the Full href of the page e.g. http://www.google.com/files/script.php?v=1.8.7&country=india
var href = window.location.href;
// Get the protocol e.g. http
var protocol = window.location.protocol + "//";
// Get the host name e.g. www.google.com
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&country=india
// Perform query functions if present
if (queries != "" && queries != "?") {
// Remove question mark ?
queries = queries.slice(1);
// Split all the different queries
queries = queries.split("&");
// 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 < length; i++) {
// Get the present query
var key = queries;
// 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 = key[0];
}
}
}
// Execute the function
$_GET();
<script>document.write($_GET['var1']);
- Tags:
- HTML5
- Intel® XDK
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For starters, where is this script running? It should run from the page that is included _into_ the iframe, not its parent.
That's a lot work to get the query. Try this:
function getQuery(name){
var queryString = document.location.search; //?v=1.8.7&country=india
queryString = queryString.substr(1); //drop ?
var pairStrings = queryString.split("&"); //["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];
}
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page