I'm using http://simplemvcframework.com and I want to link to a section on a page normally you will just add something link
#section4
to the end of the URL but this doesn't work as expected, it doesn't jump to the correct section of the page. I'm suing the following format to try and achieve this:
/controller#section4
Do I need to pass the view into the link somehow? possibly something along the lines of
/controller/viewname.php#section4
I have never used that framework before, but anchors are handled by the browser, and don't even get sent to the browser.
(I.e. when accessing /controller/#section4, the server only receives /controller/.)
It looks like you don't know about the actual use of # in URLs:
Upon loading the page, the browser will look for an element on that page with an id or name (for backwards compatibility) matching the part after the #.
So you probably just want an element with id="section4" on that page.
If you need HTML 4 support, you have to put <a name="section4">...</a> around your anchor to achieve the same effect.
(See also this question.)
Related
I'm currently generating a long page using PHP. The page also requires parameters:
http://host/showFile.php?file=abc
The resulting page can be quite lengthy and I would like to extend this to position the page at a specific line. I know how to do this using and adding #tag to the URL for an HTML file, but I can't see how to combine the effect in this case. Putting
http://host/showFile.php#tag?file=abc
doesn't work, as PHP doesn't see the file= argument, putting
http://host/showFile.php?file=abc#tag
also doesn't work as it assumes the file is then abc#tag.
I could put:
http://host/showfile.php?file=abc&line=tag
and change my code to start at the required line, but this would only show the page from the required point onward, and I need to have the whole file viewable by scrolling back.
Any ideas?
Thanks, Bill
I have a forum whereby links to a thread looks like
http://www.website.com/comments.php?topic_id=1
How can I make it look like this
http://www.website.com/1046302/some-link-desc#12154109
so that when such links are given out, the user is taken directly to that particular comment.
I'm particular about the #12154109 . The other part of the URL /1046302/some-link-desc is achieved through .htaccess configuration.
Question Update
What is the best way to get the unique number ? Do I use a timestamp or a concatenation of the topic_id and comment_id ?
You would have to apply a the following tag in the comment portion of your template.
<a name"1215409"></a>
of course the number would be set to the comment id.
You're not going to be able to do this through htaccess. The fragment, the #something part of the URL, tells the client specifics on how to handle the content that it was served, in the case of anchors, it tells the browser where to seek to in the page. The fragment is never sent to the server, so apache never sees it, and thus nothing in the htaccess file can match against it or use it in any way.
Fragments are also used by javascript which can look at the URL to pull stuff out of the fragment or to force a script to rerun by reloading the page with a different fragment.
You can, however, send fragments to the client from the server, but there's no way to know whether the client already has the fragment or not. But the content itself will need to have the fragments in the links, htaccess isn't going to know which anchors are in the actual content that ends up being served.
As some of you may know, Google is now crawling AJAX. The implementation is by far something elegant, but at least it still applies to Yahoo and Bing AFAIK.
Context: My site is driven by Wordpress & HTML5. An Custom Post Type has tree types of content, and the contents of these are driven by AJAX. The solution I came for not using hashbangs (#!) until fully understand how to implement them is rather "risqué". Every link as HREF linking to *site.com/article-one/?tab=first_tab*, that shows only the contents of the selected tab (<div>Content...</div>). Like this:
This First Tab
As you may note, data-tab is the value that JavaScript sends with AJAX Get, that gets the related content and renders inside a container. At the other side, the server gets the variable and does a <?php get_template_part('tab-first-tab'); ?> to deliver the content.
About the risqué, well, I can see that Google and other search engines will fetch *http://site.com/article-one/?tab=first_tab* instead of http://site.com/article-one/, making users come to that URL instead of showing the home page with the tab content selected automatically.
The problem now is the implementation to avoid that.
Hashbang: From what I learned, I should do this.
HREF should become site.com/article-one/#!first-tab
JS should extract the "first-tab" of the href and pass it out to $_GET (just for the sake of not using "data-tab").
JS should change the URL to site.com/article-one/#!first-tab
JS should detect if the URL has #!first-tab, and show the selected tab instead of the default one.
Now, for the server-side implementation, here is where I'm kind lost in the woods.
How Wordpress will handle site.com/article-one/?_escaped_fragment_=first-tab?
Do I have to change something in .htaccess?
What should have the HTML snapshot? My guess is all the site, but with the requested tab showing, instead of showing only the content.
I think that I can separate what Wordpress will handle when it detects the _escaped_fragment_. If is requested, like by Google, it will show all the content plus the selected content, and if not, it's because AJAX is requesting it and will show only the content. That should be right?
I'm gonna talk third person.
Since this has no responses, I have a good one why you should not do this. Yes, the same reason why Twitter banged them:
http://danwebb.net/2011/5/28/it-is-about-the-hashbangs
Instead of doing hashbangs, you should make normal URIs. For example, an article with summary tab on should be "site.com/article/summary", and if it is the default one that pops out (or is it already requested) it also should change to that URI using pushState().
If the user selects the tab "exercises", the URL should change to "site.com/article/exercises" using pushState() while the site loads the content throught AJAX, and while you still maintain the original href to "site.com/article/exercises". Without JavaScript the user should still see the content - not only the content, the whole page with the tab selected.
For that to work, some editing to the .htaccess to handle the /[tab] in the URL should be done.
my question is about this website - http://www.bits-apogee.org/2011/
whenever you click on the link in the side navigation bar, the middle part of the website is dynamically loaded. Also, the url also changes, everything else remains unchanged. how is this done?
is this some query plugin?
I totally agree with #JMCCreative. It looks like it's an actual refresh. You should look at the following post on StackOverflow.
Modify the URL without reloading the page
The site is using Hashes (#) in the URL to denote the new content being loaded.
This is useful for people bookmarking dynamically loaded content (normally hashes load to specific areas on a page, named anchors or ID's for new browsers), because they don't trigger the page to refresh...
http://www.highrankings.com/urls-with-hashtags-307 there are drawback (SEO) concerns to this... however you will notice more and more sites doing it so i would assume the SEO robots will get better.
There are 2 possibilities:
You can use the HTML5 capabilities to change the url (history pushState), however this feature isn't available in all browsers yet. For more information, look at this SO post: Is there a way to change the browser's address bar without refreshing the page? .
You can use a hashtag (#) part as fall back for browsers who don't have above feature yet.
If you use jQuery, you can use the handy plug-in jQuery Address. This will take care of both above cases.
They're not using a plugin. They're doing an ajax request to a URL like this:
http://www.bits-apogee.org/2011/getcontent/?even=Rachel+Armstrong
and dumping the overview in the container.
The circle of this type of process is usually like this:
listen for link clicks
on click, prevent default on event.
user window.history.pushState to update url
some other code - hears new history
generates a url to get the content.
ajax load the url
dump the data into a container
2 Libraries I have used, both are easier than the above, as they rely on loading a regular html page via AJAX instead the example site you point to, which used a JSON format to get the data.
Pjax - update peices of the page, by pulling that HTML node from a different URL.
Ajaxify - easiest solution, you could do that effect on an HTML site in 10 minutes.
In part of a web page, I currently link to a part of the webpage using . In other words, I link to something like:
Link 1
However, on that same link I want to include a PHP variable, which would normally look like
Link 2
Combining the two in either order just makes the page refresh, neither scrolling properly or taking the php variable. How can I use the two simultaneously?
You can concatenate the two together, just put the hash last because that is not sent to the webserver (it will be used by the browser to jump to a certain part of the page):
Link 1
When you're on the same page as the URL in your anchor, regardless of #'s value (It's called the "fragment"), the page won't even refresh, it will scroll up in hope to find an anchor that has the fitting name for the fragment
The URL fragment (everything behind # at the end of an URL) is a client-side thing, PHP won't be able to do anything with it