I actually got javascript to verify if there was a hashtag in the URL with this code:
Code:
<script type="text/javascript">
$(document).ready(function () {
if(window.location.href.indexOf("#a2") >= 0)
{
//output specific HTML
}
});
</script>
My only problem is I'm not sure how to outprint the HTML code I want there. I tried using a predefined PHP var, but to no success. Can anyone help me insert HTML with proper syntax? Here's the HTML for reference:
Why would you want to use JavaScript to write that? If that code needs to be on the page EVERY TIME the page appears, why would you not just drop it into the HTML? Why is JavaScript involved?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
when you build a single-page app, all the content of all the tabs is stored on the same page, so the hash changes don't load anything from php, so there's nothing to insert upon click either.
typically, a click on a tab link hides all open tabs, and shows the tab named in the link. in order for the tab setup to be bookmarked and history'd, use a simple onload event to find location.hash, and .click() the appropriate tab link to show the tab content specified by the url. you can also likely just raise the onhashchange() event, and let the normal handlers display the correct content.
you can also use the :target css pseudo-selector to match hashes with tab content, so that folks w/o js can still navigate the page and open/close tabs as expected (ex: div:target {display:block;})
@old penant: you want to do this so you don't have to use ajax and/or so interaction widgets are bookmark-able.
__________________ my site (updated 5/13) STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%