anchor

How to get the anchor from the URL using jQuery?

女生的网名这么多〃 提交于 2019-11-26 10:13:35
I have a URL that is like: www.example.com/task1/1.3.html#a_1 How can I get the a_1 anchor value using jQuery and store it as a variable? Nick Craver You can use the .indexOf() and .substring() , like this: var url = "www.aaa.com/task1/1.3.html#a_1"; var hash = url.substring(url.indexOf("#")+1); You can give it a try here , if it may not have a # in it, do an if(url.indexOf("#") != -1) check like this: var url = "www.aaa.com/task1/1.3.html#a_1", idx = url.indexOf("#"); var hash = idx != -1 ? url.substring(idx+1) : ""; If this is the current page URL, you can just use window.location.hash to

Opening new window in HTML for target=“_blank”

柔情痞子 提交于 2019-11-26 09:26:49
问题 <a href=\"facebook.com/sharer\" target=\"_blank\" >Share this</a> How do I make this a certain width and height, in a new window, when the user clicks on it? In firefox, the current code only opens up a new tab (not a new window) 回答1: To open in a new windows with dimensions and everything, you will need to call a JavaScript function, as target="_blank" won't let you adjust sizes. An example would be: <a href="http://www.facebook.com/sharer" onclick="window.open(this.href, 'mywin', 'left=20

ScrollTo function in AngularJS

坚强是说给别人听的谎言 提交于 2019-11-26 08:58:37
问题 I\'m trying to get a quick nav to work correctly. It\'s floating on the side. When they click on a link, it takes them to that ID on the page. I\'m following this guide from Treehouse. This is what I have for the scrolling: $(\"#quickNav a\").click(function(){ var quickNavId = $(this).attr(\"href\"); $(\"html, body\").animate({scrollTop: $(location).offset().top}, \"slow\"); return false; }); I initially placed it before the </body> . But I seem to be running into a race condition where that

How to get “raw” href contents in JavaScript

南楼画角 提交于 2019-11-26 08:23:54
问题 I am trying to write a GreaseMonkey script in which I want to find all of the links that are relative links. It seemed to me that the way to do that would be to match the contents of href against /^https?:/// . But I find that when I access the anchor\'s href attribute, it\'s always normalized or cooked into a form that contains \"http\". That is, if the HTML contains: <a id=\"rel\" href=\"/relative/link\">inner</a> accessing document.getElementById(\"rel\").href returns http://example.com

Programmatically scroll to an Anchor Tag

删除回忆录丶 提交于 2019-11-26 08:09:24
问题 Consider the following code: <a href=\"#label2\">GoTo Label2</a> ... [content here] ... <a name=\"label0\"></a>More content <a name=\"label1\"></a>More content <a name=\"label2\"></a>More content <a name=\"label3\"></a>More content <a name=\"label4\"></a>More content Is there a way to emulate clicking on the \"GoTo Label2\" link to scroll to the appropriate region on the page through code? EDIT : An acceptable alternative would be to scroll to an element with a unique-id, which already exists

anchor jumping by using javascript

帅比萌擦擦* 提交于 2019-11-26 07:57:44
问题 I have a question that will be found very often. The problem is that nowhere can be found an explicit solution. I have two problems regarding anchors. The main goal should be to get a nice clean url without any hashes in it while using anchors to jump on a page. So the structure of the anchors is: <ul> <li><a href=\"#one\">One</a></li> <li><a href=\"#two\">Two</a></li> <li><a href=\"#three\">Three</a></li> </ul> <div class=\"wrap\"> <a name=\"one\">text 1</a> <a name=\"two\">text 2</a> <a

Make anchor link go some pixels above where it&#39;s linked to

孤街醉人 提交于 2019-11-26 07:54:21
问题 I\'m not sure the best way to ask/search for this question: When you click on an anchor link, it brings you to that section of the page with the linked-to area now at the VERY TOP of the page. I would like the anchor link to send me to that part of the page, but I would like some space at the top. As in, I don\'t want it to send me to the linked-to part with it at the VERY TOP, I would like 100 or so pixels of space there. Does this make sense? Is this possible? Edited to show code - it\'s

Valid to use <a> (anchor tag) without href attribute?

我的梦境 提交于 2019-11-26 06:59:13
问题 I\'ve been using Twitter Bootstrap to build a site, and a lot of its functionality depends on wrapping things in <a> , even if they\'re just going to execute Javascript. I\'ve had problems with the href=\"#\" tactic that Bootstrap\'s documentation recommends, so I was trying to find a different solution. But then I tried just removing the href attribute altogether. I\'ve been using <a class=\'bunch of classes\' data-whatever=\'data\'> , and having Javascript handle the rest. And it works. Yet

Cross-reference (named anchor) in markdown

ε祈祈猫儿з 提交于 2019-11-26 06:51:50
问题 Is there markdown syntax for the equivalent of: Take me to <a href=\"#pookie\">pookie</a> ... <a name=\"pookie\">this is pookie</a> 回答1: Take me to [pookie](#pookie) should be the correct markdown syntax to jump to the anchor point named pookie. To insert an anchor point of that name use HTML: <a name="pookie"></a> Markdown doesn't seem to mind where you put the anchor point. A useful place to put it is in a header. For example: ### <a name="tith"></a>This is the Heading works very well. (I'd

How can I disable HREF if onclick is executed?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 06:41:05
问题 I have an anchor with both HREF and ONCLICK attributes set. If clicked and Javascript is enabled, I want it to only execute ONCLICK and ignore HREF . Likewise, if Javascript is disabled or unsupported, I want it to follow the HREF URL and ignore ONCLICK . Below is an example of what I\'m doing, which would execute the JS and follow the link concurrently (usually the JS is executed and then the page changes): <A HREF=\"http://example.com/no-js-login\" ONCLICK=\"yes_js_login()\">Log in</A> what