I am trying to copy a link from this site (stack overflow), but I like the link to include a hash so when someone clicks on the link they go directly to the answer I would like them to see. How can I find the hashes in a page?
Example:
http://www.blahblah.com/index.php#label
How can I know there is a #label, and how to find it?
The value of the hash is simply the ID attribute of any element in the page.
You can see them in the source or the DOM inspector.
Are you looking for something like this?
var hash = window.location.hash;
There might not be a simple answer for your here. In a pure HTML context (i.e. excluding javascript functionality). The has would reference an anchor on the page like this:
<a name="label"></a>
So you could just look for named anchors.
Now, if you are talking about javascript functionality it gets much more complex. Via javascript you can use a hash tag like that and make it do any number of things (like show a hidden element with id="label", download some content asynchronously based on that hash, etc. So there might not be an easy way to determine allowable values.
Related
I'd like to refer to a specific part of a web page which I am not the author of, and which is not tagged with the NAME attribute. The specification of the part I have in mind could be made, e.g., as the location a certain word appears, and which could be manually reached via a FIND operation. I imagine something like
http://somesite.com#search-for:foo-bar
Is there some feature in HTML allowing for this?
No.
You can only link to elements with an id and a elements with a name.
i use filters/tags on my webapp to sort articles dynamically. now these filteres do not really match microformat.org's idea of rel="tag" (no url, not a tag, i don't know), but i don't see any other way to avoid google seeing it as keyword stuffing.
is there a better way so highlight these "tags" or would you
encourage me to use rel="tag".
see it yourself: http://www.rewow.de/eiweisspulver/
thank you very much!
Clicking one of the "tags" changes the content of the page using JavaScript.
Your JavaScript should be unobtrusive and progressive.
They should be links with URLs and if the JavaScript fails, then you can generate the same content on the server. (You can use pushState to make the address bar match the target page when you successfully transform the current one into it with JS).
That way they match microformat.org's idea of rel="tag", and your site is more reliable and search engine friendly.
2 questions about a better way of solving the problem:
1) is there is a way to make HTML page title looking different for different locales of the client-side code except for javascript?
I.e. write HTML page title which is shown in the browser's tab in corresponding language.
I know I can use javascript for this, but may be there is another way?
2)I set my HTML page header with javascript (it is a different case). But there is a delay before the script will run. Is there is a way to set HTML page header to empty line before javascript evaluates?
If I remove tag I get the page URL.
If I use empty tag - same thing.
I have to use   content inside which looks a bit ugly.
Some other options?
I don't see any other means but JavaScript on the client side for this, sorry.
For the delay: try using an inline javascript to change the page title right on top of the page before any other scripts are loaded or executed, but after the page title has been set. This should keep the delay to an absolute minimum.
To the first:
Except Javascript, the only Way i know would be PHP, but using Javascript is a lot better and
easier.
To the second:
arkascha's Post is the answer
For example:
http://www.example.com/index.html#foo?key=value
When page is loaded, it goes to the bottom of the page. Any clue?
In HTML5 you just need to set the hash to an ID of any DOM node on the page and it should move the page down in the same way as old style page anchors.
Anything after the hash can only be accessed by JavaScript so if you want to get the value of key you will need some JavaScript to do so.
EDIT: Here is a good tutorial for storing and retrieving several attributes from the hash string - http://www.parorrey.com/blog/php-development/get-url-hash-parameters-values-using-javascript-for-php-_request/
You can read about anchor tags but you querystring is the wrong side of the hash. It should read:
http://www.example.com/index.html?key=value#foo
I'm trying to add localization support to a Google Chrome Web App and, while it is easy to define strings for manifest and CSS files, it is somewhat more difficult for HTML pages.
In the manifest and in CSS files I can simply define localization strings like so:
__MSG_name__
but this doesn't work with HTML pages.
I can make a JavaScript function to fire onload that does the job like so:
document.title = chrome.i18n.getMessage("name");
document.querySelector("span.name").innerHTML = chrome.i18n.getMessage("name");
but this seems awfully ineffecient. Furthermore, I would like to be able to specify the page metadata; application-name and description, pulling the values from the localization files. What would be the best way of doing all this?
Thanks for your help.
Please refer to this documentation:
http://code.google.com/chrome/extensions/i18n.html
If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. That is the only way you can do it.
chrome.i18n.getMessage("name")
It isn't inefficient to do that, you can place your JavaScript at the end of the document (right before the end body tag) and it will fill up the text with respect to the locale.
Dunno if i understand exactly what you are trying to do but you could dynamically retrieve the LANG attribute (using .getAttribute("lang") or .lang) of the targeted tag and serve accordingly the proper values.