Results 1 to 4 of 4

Thread: Additional functionality with script

  1. #1
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Additional functionality with script

    1) Script Title:
    Dynamic Ajax Content

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...tent.htm#combo

    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

    http://mypage.com/index.html#porsche

    or

    http://mypage.com/index.html?ref=porsche

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

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    Put something like this at the end of the index.html page, right before its closing </body> tag:

    Code:
    <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');
    }
    </script>
    Then you can have a link like:

    http://mypage.com/index.html?ref=porsche

    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).
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    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"

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    The simplest way would be to use the extended path in the link, instead of:

    http://mypage.com/index.html?ref=porsche

    use:

    http://mypage.com/index.html?ref=cars/germanCars/porsche

    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:

    http://mypage.com/index.html?ref=porsche&path=cars/germanCars/

    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:

    Code:
    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:

    http://mypage.com/index.html?ref=cars/germanCars/porsche
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Seeking script with this functionality
    By galina in forum Looking for such a script or service
    Replies: 2
    Last Post: 05-21-2010, 04:17 PM
  2. Insert two additional divs in menu script
    By glhf in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-14-2010, 07:07 PM
  3. Dynamic Image selector Additional functionality?
    By Aledopcworks in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-13-2008, 02:49 AM
  4. Additional option for script
    By atlantic in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-08-2007, 02:16 PM
  5. Add additional p tag to Photo Album script?
    By shirster in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 11-03-2006, 08:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •