I am actually stumped on HTML.. can't believe it.
So, I have a submenu which is powered by JavaScript.
<span>SubPage</span>
I have deleted my JS and it still happens so I obviously misunderstand something.
When I load a page its a bit slow and I have time to hit the sub menu button. If I keep tapping this while the page is loading, instead of putting the hash on the end of the url and not changing the page it is taking me /dir/# which is resetting the page.
Any idea why?
Maybe the page is still in your browsers cache. Look at the source to make sure the JS is not there, or press Ctrl+F5.
Most JS coding is done after page has finished loading to make sure the elements are there.
Common solution to the problem you describe is have the link hidden (CSS style) or disabled by default then show or enable it in the JS code.
Basic example:
<a href="#" class="subpage" disabled="disabled">
Then in the JS code add something like this:
oLink.disabled = false;
Edit: Stupid me! Just change the href to:
href="javascript:void(0);"
This way clicking it won't have any effect until the JS kicks in.
Related
I have a link on a page like this
use our contact form.
Then in about-us.php I have
<div class="extra" id="contactform">
When I click the link, the browser takes me to the correct page BUT
The address bar momentarily flashes up "about-us.php#contactform"
Then it falls back to "about-us.php#" and the browser doesn't move to the anchor.
This is so simple, yet I can't see what is causing it. I have several other anchors with exactly the same format that are working. I also have a link that is called from PHP to the same anchor, and that works.
Mystified!
PROBLEM SOLVED
It was the PHP and Javascript bit of the overall page code that caused the problem. It was overriding the anchor link. Having wrapped the javascript in a PHP if() statement, it is under control.
Moral of the story: look at everything and not just the bits close to the apparent problem.
I have a drop down menu which I include on all my pages using php. On this menu I am using anchors to navigate to various divs on a single page. It is very simple code, anchors with tags in the href, no JavaScript.
Test
navigates to
<h2 id="test">Test</h2>
If I am navigating to the page this works fine. If I am already on the page it goes to the tag then redirects back to the page without the tag (i.e. goes from test.php#test to test.php). What is causing this behavior and how do I fix it?
If you had provided more code then it would have been more helpful. But I am just guessing here what the problem is. You can add the following javascript to your page:
$("a[href^=#]").on("click", function(e) {
e.preventDefault();
history.pushState({}, "", this.href);
});
What this does is target all hash-links and prevent their default behavior and change the URL. But without seeing more of your code, its hard to tell if it'd work. You can also interchangeably use replaceState, which would change the URL without adding an entry to the browser history. Code borrowed from here.
I’m trying to make web scraping in a web page, but there is code that I can’t reach. The part of the code of the page that I cannot achieve is accessed through an anchor tag. In the html is:
<a class="MTLink" href="#d192633539-47" title="example" >
But when I click on "#d192633539-47" does not appear what is intended, ie not appear that appears when I click on the link on the page. Instead appears another page.
Related to this I have also
<li id="d192633539-47" class="MainTabContent Hidden" tnIndex="192633539">
Someone can help me? What could be happening?
This element is controlled by JavaScript. Without tracing the JS code you cannot determine the intention of the click event.
There might be a problem with wrong cookie handling. Check it out.
I want to open HTML page itself in a new window.
After clicking at the button I want that page will open in a new window. But I dont want to edit main page where the button is located, but I want to edit that page, which will be opened after clicking.
Is that possible without using JavaScript?
No, what you want to accomplish is not possible without JavaScript. As #Piszu somewhat answered, you need to define this behavior either though JavaScript or through the target attribute of links pointing to it.
I may add as a matter of opinion that the more you try to fight default browser behavior, the more headaches you'll run into. There probably isn't a very good reason to be doing whatever it is that you're trying to accomplish.
<a href="http://yourLink.com" target="_blank" title="describe link">
Do you mean like this?
But edit page opened in new window without script is not possible.
I have a code snippet that is installed on third party websites. I can't get into the details, but it loads HTML, CSS and JS onto the page through the use of a <script> tag.
Part of the code is a JS function that executes when this link is clicked:
?
If there are JS errors on the page that prevent the function from executing, clicking the link obviously just adds the hash to the URL and takes the user to the top of the page. This is the expected fallback behavior.
However, on one third party site with a multitude of JS errors, clicking the link removes everything after the top level domain, adds the hash, and directs to that page (the home page). For example, the link would take the user from:
http://www.example.com/2010/05/14/very-interesting-blog-post/
to
http://www.example.com/#
Notably, the issue occurs in Firefox and Chrome, but not IE9. I know it may be impossible to properly diagnose the issue without more detailed code, but I'm not at liberty to provide it. I'm just hoping to get some kind of reasonable explanation for this strange browser behavior.
If it helps at all, the site in question is a WordPress blog. Thanks in advance.
EDIT: This is apparently not caused by any JS on the site, because turning off JS and adding the link with the inspector produced the same behavior.
I had a similar error where clicking on any <a href="#"> causes a full page reload. I managed to solve this by removing the <base href="/"> tag from the <head> of the page. I couldn't find any informations on this (yet). I'll add more if I can find any additional info.
This problem happens when you use windows.onpopstate to handle back or forward buttons and load page using ajax. Try to solve your js code for handling history.