Okay, In HTML, preferably 5, is there a way to set a link to take the user to a specific place on an external? I know I can link to an anchor
<a href="#blahblah"> goes to <a name="blahblah">
but what i need to to act as if my anchor is on someone else's page, where I cannot insert an anchor. Help me out?
Yes. Just use the hash after your root URL, like so:
or
However, if there is no anchor on the other page or you aren't in control of that page, then I'm afraid there is not a way to do that.
Related
I wanted to make a header with navs (local website) , and the same header will be repeated in all pages.
So instead of copy pasting it, i made a custom element in js.
The problem is that the hrefs in the main page will be different than the other pages.
This is how it should be in the main page
<a href="pages/somepage.html">
And this is how it should be in other pages who are in the same folder
<a href="somepage.html">
Using a custom element will make them all have the same href.
Is there a solution to this or am i missing something really obvious ?
I could just have them all in the same folder but that will get messy the more pages i add.
Make your href absolute by putting a / at the front.
eg
<a href="/pages/somepage.html">
Maybe you make links following:
<a href="/pages/somepage.html">
if you add / to front link browser search the folder.
all sorry for the very basic or maybe a silly question but I was trying to do something which I am not sure, can be done by using an anchor tag or not. After searching over the internet I didn't find any perfect solution for that so here I am writing this question.
Problem - I want to redirect my page from index.php to about.php, and I also want to open one div that can be only visible if we click on it. How to do that using an anchor tag?
I tried - <a href="about#my_div_id">
unfortunately, It didn't work I think maybe because I have to also click on that particular div to make it open.
Anyone can please help me out I need some solution to do this. I am using angularJs so if it can be done by that, please help!
Could you parse the URL in JavaScript on page load, open the div, and set document.documentElement.scrollTop to the position of the div on your page?
Something like:
# On page load:
# if $parsedURL has $hash:
# div.show()
# window.scrollTo(div.position)
I need to use js to force the browser to go to the anchor tag #showcase in the home page of mysite.com:
mysite.com/#showcase
If someone enters the url mysite.com though, I want the browser to load the page normally.
This should be a fairly simple if/else script surely, but having trouble finding a good cross-browser script that works.
you could use the following code
window.location.replace("#showcase")
Don't need to use any JavaScript for this.
You have to place your anchor tag in your home page like this:
showcase
Make sure that the id is the same as your url parameter. In the example above, the id is equal to the url you want.
This will work for any element you have, just make the id the same as in the url.
I made a simple codesandbox, here is the link:
https://codesandbox.io/s/url-anchor-tag-c3tw5?file=/index.html
This has the if statement you're looking for:
element = document.querySelector('#element-id')
if (location.hash == '#showcase') element.scrollIntoView()
on the site example.html i have the link href="index.html#section1".
when you click the link, the url is index.html#section1, but is there a way to only display index.html but still go to the Id #section1 ?
I found this: Removing anchor (#hash) from URL
but i don't know how to use it since i only understand a little javascript. maybe someone can help out with a detailed instruction where to insert which code.
You can't change the data after the hash without re-directing the page but you can re-name it with
location.hash = "new-location"
I have a page containing two separate iframes(header and navigation), which have some links inside. (I know it sucks. I have to do this, because the header and navigation are actually from another project)
When I click the links inside the iframes, only the relevant iframe changes. While what I want is that when I click the link, the whole page, namely the current window, changes to that new URL.
I know javascript injection is not possible and I can't append a <base target='_top'> into iframes' <head>.
Is there any way I can achieve what I want? Or if you have a better way other than <iframe>, please don't hesitate to tell me. I'm still a novice in Front-End engineering. Any help will be appreciated.
Add target="_top" to the links in the frames, e.g.
Click me
Same domain? Go to town and inject a tag, or modify all of the a tags to have a target. I can add more info on how to do it if needed.
Edit
Here's a jsbin page for completeness:
http://jsbin.com/osoji4/10