View Full Version : Additional functionality with script

10-23-2013, 11:58 AM
1) Script Title:
Dynamic Ajax Content

2) Script URL (on DD):

3) Describe problem:

The script is working perfectly but I need extended functionality on my page and I'm sure it can be done via js
Let's say for example I want the user to directly be referred to the "Porsche" bullet and I need to give him a link. Right now that's impossible it just redirects him to the porsche.html and I want him to be directed to the fully formatted bullet

Let's say I'm giving the following link




I need the user to be able to directly go to the content


10-23-2013, 02:18 PM
Put something like this at the end of the index.html page, right before its closing </body> tag:

<script type="text/javascript">
function getQval(n) {
if(typeof n !== 'string'){
return null;
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;
if((ajaxpage.page = getQval('ref'))){
ajaxpage(ajaxpage.page + '.html', 'content');

Then you can have a link like:


This assumes the page you want is porsche.html and that the target div on index.html has a unique id of content and that porsche.html is in the same folder as index.html. If things are different, adjustments can be made to the script code I just gave you to compensate and/or more information can be passed in the link.

If you have a server side language like PHP, it can handle the duties of parsing the link to determine if something should be initially loaded in the content area, and can even load it (include it).

10-28-2013, 01:51 PM
This is very helpful, works perfectly and Im very thankful. But let's say that html files aren't in the same folder, how can I point this line of code
if((ajaxpage.page = getQval('ref'))){
ajaxpage(ajaxpage.page + '.html', 'content');

to a folder within my structure ?

Let's say the porsche.html file resides in the folder and sub-folder "cars/germanCars/porsche.html"

10-28-2013, 02:31 PM
The simplest way would be to use the extended path in the link, instead of:




Other alternatives would be to have more than one variable passed in the string (each additional passed variable would be parsed to see what if any additional path information it signified) like:


But that would require additional decoding code. Or a way to get the path from the variable passed. The latter would require a sort of database of which thing is in which place. A lookup object:

var pages = {
porsche: 'cars/germanCars/porsche.html',
chevy: 'cars/americanCars/chevy.html',
nokia: 'phones/mobilePhones/nokia.html'

Then if the ref is found in this object, it's value is used as the path and filename. But, this last is the most work because you would have to setup and maintain this lookup object.

So, unless you have some objection to showing the path in the query string of the link, I'd go with the first most simplest option: