when you click on the link a new page html page opens and on that new page, information found in a database with the id of 12(as found in the link) will be displayed using external style sheets etc. Can this be done with html css javascript and json? P.S I know how to do this with php however I want this to be done in my mobile app so the actual page cannot be a .php page
You can either add a querystring parameter to the href which the receiving page reads, or use an onclick handler to store a parameter either in a cookie or in sessionStorage.
And in that sitesClickHandler function you can check to see if it was a link that was clicked on, then take action.
function sitesClickHandler(evt) {
evt = evt || window.event;
var targ = evt.target || evt.srcElement;
if (targ.nodeType === 3) {
targ = targ.parentNode; // Fix browser bug
}
if (targ.nodeName === 'A') {
processClickedLink(targ);
return false;
}
}
That processClickedLink function will do want you want with the link, and from there you can also check the querystring. You can get the querystring from the search property of the link.
function processClickedLink(link) {
var qs = link.search;
...
}
Given the initial href of “newpage.html?style=12”, the qs variable would now contain a string value of “?style=12”
You can get the number 12 by something like:
var matches = qs.match(/style=(\\d+)/);
var number = Number(matches[1]);
Do you mean your link to navigate to a new page on which some styling is determined by the querystring, or stay on the current page and alter something on it?
My interpretation was the first scenario, in which case you don’t need to worry about onclick handlers.
I want to go to a new page to change the styling of original page and present new data. If I don’t need a handler then what can I use then
btw in php this is soo much easier.
ok I dont think I am being understood in php you can have dynamic links which have a value of for example ?id=12. When you click that link it would open a new php page but produce information on the new page based on the value of ?id=12. Now what php is doing with dynamic links I would like to do that with html
javascipt php and json. The reason for this is because I am building my app in phonegap.
You really ought to use something other than id as the name for your variable so as to avoid getting it confused with the HTML attribute of that name which can be the target of an <a> tag.
For example:
<a href=“page1.htm#a12”>text</a>
would link to page1.htm and then scroll to put the element with id=“a12” at the top of the page.