admin管理员组文章数量:1404924
i am using this for Phonegap so,i would prefer the solution in javascript.
i found many solutions using PHP.thats why i thought of making it clear.
well i get an array,whose vales are from the database.I want to pass this array to the SECOND HTML PAGE.
to pass a variable the following code is being used...
EDIT:
window.location.href="1stpage.html"?var1=&value;
hope, i am right with the coding.
Please,guide me,if i am wrong.
changes with reference to the answer suggested
Julio Meca Hansen Sir,i tried implementing the same
window.location.href='1st page.html?var1=5&var2=6';
and tried verifying it by printing the values on the second page...
console.log("value1: "+var1 +"value2: "+var2 );
alas!,i get this error...
E/Web Console(12476): ReferenceError: Can't find variable: var1 at file:///android_asset/www/1st%20page.html?var1=5&var2=6:17
i am using this for Phonegap so,i would prefer the solution in javascript.
i found many solutions using PHP.thats why i thought of making it clear.
well i get an array,whose vales are from the database.I want to pass this array to the SECOND HTML PAGE.
to pass a variable the following code is being used...
EDIT:
window.location.href="1stpage.html"?var1=&value;
hope, i am right with the coding.
Please,guide me,if i am wrong.
changes with reference to the answer suggested
Julio Meca Hansen Sir,i tried implementing the same
window.location.href='1st page.html?var1=5&var2=6';
and tried verifying it by printing the values on the second page...
console.log("value1: "+var1 +"value2: "+var2 );
alas!,i get this error...
E/Web Console(12476): ReferenceError: Can't find variable: var1 at file:///android_asset/www/1st%20page.html?var1=5&var2=6:17
Share
Improve this question
edited Apr 19, 2013 at 11:10
user
asked Apr 18, 2013 at 11:55
useruser
1,0014 gold badges21 silver badges46 bronze badges
6
-
Your code is invalid - JS is different from HTML, you don't wrap them between
<
and>
signs ;) – Terry Commented Apr 18, 2013 at 12:01 - oops, Sorry.i may be stand corrected! – user Commented Apr 18, 2013 at 12:06
- This is an unusual scenario since you risk the user being able to alter the data. Usually you'd re-retrieve the data from the database between pages. – NibblyPig Commented Apr 18, 2013 at 12:34
- 1 @SLC I beg to differ - sometimes passing strings or arrays between pages can be important, such as a multistep form (well, you can technically do that with cookies, but that doesn't make them any more secure). Pagination leverages a lot on passing various variables between pages, too. – Terry Commented Apr 19, 2013 at 7:53
- 1 There are a bunch of reasons why I would never personally do that, such as server side validation, or the user pressing the 'back' button in the browser, or pressing F5, or if a validation error occured on page 1 and you were on page 4, you'd have to get back there and have a nightmare of ensuring you don't lose the information from page 2, 3, 4 when you press 'next' after correcting the mistake. Lots of unnecessary baggage in my opinion, and a monstrosity to program and maintain. – NibblyPig Commented Apr 19, 2013 at 11:11
4 Answers
Reset to default 2If this array will only be used by JavaScript, then do NOT use a cookie. Cookies are for storing information that the server needs access to, and setting them willy-nilly can increase your network usage by a significant amount!
Instead, use JavaScript's localStorage
interface. It is supported by all modern browsers (IE7 and below don't count as "modern", especially with Windows Update practically forcing you to update), and is real easy to use:
var someArray = [1,2,3,4];
if( !window.localStorage) alert("Sorry, you're using an ancient browser");
else {
localStorage.myArray = JSON.stringify(someArray);
}
Later, you can retrieve it: JSON.parse(localStorage.myArray)
I hope this is what you are trying to achieve. If not, please clarify your question some ;)
If the code is linked to an image, it would be more like this:
<img src="images/img1.png" alt="" onclick="window.location.href='1stpage.html?var1=5&var2=6';">
Modify it to fit your needs :P
If you don't want to use javascript:
<a href="1stpage.html?var1=5&var2=6">
<img src="images/img1.png" alt="" />
</a>
I have assumed you are using jquery but the principle is the same in plain old js - use a cookie e.g.
how to store an array in jquery cookie?
This actually stores the array rather than a load of variables as described in other answers.
本文标签: javascripthow to pass an array from one html to another html pageStack Overflow
版权声明:本文标题:javascript - how to pass an array from one html to another html page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744874045a2629807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论