Skip to content Skip to sidebar Skip to footer

Open In New Tab With Dynamic Content

for this example I'm going to use a property site. If at the top of the site I had the main viewed property ad, and below a whole lot of small square divs with the other ad's. Now

Solution 1:

You need to use a hashtag function and append a hash value onto the URL. So the square divs would actually be links like:

<ahref="http://your-site.com/page#advert1">Ad 1</a><ahref="http://your-site.com/page#advert2">Ad 2</a><!-- Ad3, Ad4 etc. -->

Here's an example of the jQuery you could use to read the hashtag:

// CHECK IF A HASHTAG EXISTS IN THE URLif(window.location.hash.length > 2) {
    // GET THE HASHTAG NAMEvar advert = window.location.hash.replace('#', '').replace(/\/$/, '').substr(1);

    // THEN CALL FUNCTION TO GET AD CONTENT FROM YOUR ARRAY USING THIS INFO
}

Alternatively you could use a plugin for this like jQuery Address which is made for this exact thing and has a load more features including the capture of hashchange events and click tracking for Google Analytics.

Post a Comment for "Open In New Tab With Dynamic Content"