iwato Posted July 25, 2009 Share Posted July 25, 2009 QUESTION ONE: Is there a standard method for passing variable values from one-page to the next in a client-side environment?QUESTION TWO: If so, what is it?QUESTION THREE: Can more that one variable value be passed at the same time?Roddy Link to comment Share on other sites More sharing options...
boen_robot Posted July 25, 2009 Share Posted July 25, 2009 Yes, but it's only supported in the latest versions of IE (8), and Firefox (3.5).They call it "DOM Storage" - https://developer.mozilla.org/en/DOM/Storage, http://msdn.microsoft.com/en-us/library/cc197062(VS.85).aspx, http://en.wikipedia.org/wiki/DOM_storageYes. DOM Storage stores the values in an object. Values inside an object in JavaScript can be accssed similarly to associative arrays in PHP. Link to comment Share on other sites More sharing options...
Ingolme Posted July 25, 2009 Share Posted July 25, 2009 You can always append them to the query string and then read them back from the query string in the other page.Page 1: x = 1;y = 5;location.href = "page.html?x=" + x + "&y=" + y; Page 2: // The following instruction simulates PHP's $_GET array:$_GET = function() { var w=window.location.search,s='substring' var it, qS, i=0, qV=[]; qS = w[s](1).split('&'); while(i < qS.length) { it = qS[i].split("="); qV[it[0]] = it[1]; i++ } return qV;}();x = $_GET['x'];y = $_GET['y'];alert("x + y = " + (x + y) ) Link to comment Share on other sites More sharing options...
iwato Posted July 26, 2009 Author Share Posted July 26, 2009 You can always append them to the query string and then read them back from the query string in the other page.Thank you for responding, Ingolme.I tried what you suggested, but ran into difficulty.1) If I assign as page.html the previous page, the next page does not read the code.2) If I assign as page.html the next page, the code is read by the next page, but the previous page never appears.My objective requires that both pages, the previous page and the next page, can be viewed.Also, I do not understand the meaning of the expression w(1) in the statement qS = w(1).split('&'). Surely, the brackets refer to the element of an array called w, but what does it indicate when you add the expression (1).Finally, I do not know how to exit the continuous looping created by the following snippet:<script type="text/javascript">x = 1;y = 5;location.href = "countingTags1.html?x=" + x + "&y=" + y;</script>The countingTags1.html refers to the previous page.Roddy Link to comment Share on other sites More sharing options...
iwato Posted July 26, 2009 Author Share Posted July 26, 2009 Yes, but it's only supported in the latest versions of IE (8), and Firefox (3.5).I am happy to learn that the world has not given up on client-side interactivity in same way that I have given up on Microsoft's Internet Explorer, but are you suggesting that recent versions of Safari and Opera do not acknowledge DOM storage?I can encourage my viewers to avoid Microsoft, but to tell them that the only browser they can use is Firefox would likely be demanding too much.Roddy Link to comment Share on other sites More sharing options...
Ingolme Posted July 26, 2009 Share Posted July 26, 2009 As proof that the Javascript works properly, here's a link to your page assigning 1 to x and 2 to y: countingTags2.html?x=1&y=2. Sadly, it's concatenating the numbers rather than summing them. That can be solved with parseInt(). Also, I do not understand the meaning of the expression w(1) in the statement qS = w(1).split('&'). Surely, the brackets refer to the element of an array called w, but what does it indicate when you add the expression (1). In Javascript, objects and associative arrays are equivalent. Writing window.location is the same as writing window['location'].Putting () after anything makes the parser attempt to run it as a function.I combined these two features in order to shorten up my code: // Given that:w = window.location.searchs='substring' // This:w[s](1); // is equivalent to:window.location.search['substring'](1) // which is equivalent to:window.location.search.substring(1) Finally, I do not know how to exit the continuous looping created by the following snippet:<script type="text/javascript">x = 1;y = 5;location.href = "countingTags1.html?x=" + x + "&y=" + y;</script> The reason it's looping is because you are loading the exact same page. location.href tells the browser to open the specified URL. Try loading a different page instead, or have the code only be activated by a button:<button type="button" onclick="location.href = 'countingTags1.html?x=' + x + '&y=' + y">Click here</button> In order to pass the variables from one page to another, you have to append them to the URL and open the page with that URL. Link to comment Share on other sites More sharing options...
iwato Posted July 26, 2009 Author Share Posted July 26, 2009 Sadly, it's concatenating the numbers rather than summing them. That can be solved with parseInt().No problem, and the rest was just as easy with your terrific explanations! I am now confident that I can pass information from page to page -- well, at least until I stumble on my next unknown. Many thanks, Ingolme.Roddy Link to comment Share on other sites More sharing options...
rnd me Posted July 26, 2009 Share Posted July 26, 2009 but are you suggesting that recent versions of Safari and Opera do not acknowledge DOM storage?Safari4 does, but Opera doesn't support much of anything that's not published in a 5 year old spec... Link to comment Share on other sites More sharing options...
boen_robot Posted July 26, 2009 Share Posted July 26, 2009 Safari4 does, but Opera doesn't support much of anything that's not published in a 5 year old spec...Offtopic://I'm not sure I agree with this. Opera (10 at least) passes the Acid3 test (thus it has (nearly?) complete DOM 2 support, CSS 3 colors, CSS3 selectors, etc.), and even version 9.5 has better SVG support that all other browsers, including support for SVG as background-image and SVG fonts in (X)HTML. It also supports APNG and MathML. Combined, this is more than what can be said for Safari 4 or heck, even Firefox 3.5. With that said, yes... if Safari 4 has support for DOM storage, then Opera is the last one remaining. Link to comment Share on other sites More sharing options...
rnd me Posted July 27, 2009 Share Posted July 27, 2009 Offtopic://I'm not sure I agree with this. Opera (10 at least) passes the Acid3 test (thus it has (nearly?) complete DOM 2 support, CSS 3 colors, CSS3 selectors, etc.), and even version 9.5 has better SVG support that all other browsers, including support for SVG as background-image and SVG fonts in (X)HTML. It also supports APNG and MathML. Combined, this is more than what can be said for Safari 4 or heck, even Firefox 3.5. With that said, yes... if Safari 4 has support for DOM storage, then Opera is the last one remaining.yes, it does support a lot of seldom-used specs, though in fairness, most of your example specs were introduced several years ago.As far as acid3: i sure hope Opera does well since the author of acid3 is the brains behind Opera!javascript features, not document features, is where Opera is still far behind the pack.eg: domStorage, postMessage, showModalDialog, document.activeElement, elementFromPoint, etc. While i agree that v10 will be a huge leap forward, the thing that bothers me about Opera is that they adhere more to W3 recs than WHATWG, even though Hixie started WHATWG! Link to comment Share on other sites More sharing options...
Ingolme Posted July 27, 2009 Share Posted July 27, 2009 I prefer browsers to adhere to the W3C recommendations than to add their own features (Internet Explorer had it's share of proprietary features). That way every browser will behave the same, making developing applications much easier. Link to comment Share on other sites More sharing options...
boen_robot Posted July 27, 2009 Share Posted July 27, 2009 domStorage and postMessage appear in the HTML 5 draft... I suppose Opera is behind because it hopes for the APIs to become more stable (same excuse as to why IE is behind supporting CSS 3 features, only many CSS 3 features are more stable than those APIs). As for the rest you mentioned, they're all proprietary features that happen to be reverse engineer by other browsers. See the pages on MSDN for showModalDialog, activeElement, elementFromPoint. Look under "Standards Information". In all three, it says there is no standard.I too prefer to have support for W3C specs over support for proprietary features. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.