Please help me on this how can i use hash function to go to another tab or id without location.reload();.
it should be needed to go to the download tab or id without needing to refresh the page.
here is my code
<script>
function Download() {
window.location.hash = "#Download";
location.reload();
}
</script>
Do you actually need to use JavaScript for this? What about just using #href attributes to go to another <a> link on the page?
Something like this:
<a id='first' href='#second'>Go to Second Link.</a>
<a id='second' href='#first'>Return to First Link.</a>
See this fiddle for example: https://jsfiddle.net/3axqpr1x/1/
you can try this one;
<script>
function Download() {
window.location.hash = "#Download";
location.reload();
}
</script>
Please refer this page Javascript reload the page with hash value
Related
I'm developing one Flipbook by using html, css, js. Also, i have included video files with the Book. The problem with the book is, When i load the book for the first time, video file is working, after flipping Video is not working. I found what the problem is. It needs to be refreshed when each page turns.
The following is the code which i'm using to call the video file.
<a class="voverlay" id="sk" href="index_videolb/vdbplayer.swf?volume=100&url=video/change1.mp4" onclick="javascript:myfunc();"><img src="index_videolb/thumbnails/change1.png"/></a>
<script>
function myfunc()
{
location.reload(true);
}
</script>
The problem with the code is, It only access the Onclick function, not href.
Is there anyother way to access both href and onclick?
If you have both href and onclick, href would override any onclick behaviour. To avoid that you can do,
<script>
function myfunc(event)
{
event.preventDefault();
location.reload(true);
}
</script>
Try this
function myfunc() {
window.location = "index_videolb/vdbplayer.swf?volume=100&url=video/change1.mp4";
}
I am trying to create a link in JS that moves the person the page from where he has come from. Here is the code.
<script language="javascript">
function Jump()
{
document.href=document.referrer;
}
</script>
Here is the html,
Skip and Continue
Now when the user clicks on the link, nothing happens. Please guide me where I am doing wrong. Thanks
how about using the below code to move back
history.back();
Many browsers will not use document.referrer for privacy reasons, especially if the referrer is from another domain.
Instead, try onclick="history.go(-1)" instead of your Jump() function.
It is better to bind a click listener than use onclick.
Try changing it to this:
<a id="myLink" href="#">Skip and Continue</a>
And Javascript:
<script type="text/javascript">
document.getElementById('myLink').addEventListener('click', function(e) {
e.preventDefault();
document.location.href=document.referrer; //actually better as "history.back()"
}
</script>
It is not document.href but window.location.href...
<script>
function Jump(){
if(document.referrer)location.href=document.referrer;
else history.back();
}
</script>
(If you used the jump to get to the current page, there is no referrer.)
I am trying to get the childBrowser plugin to work on links by adding the code at runtime to links.
Normally, if I was adding to code manually to the links, this is how it would look:
<a href="#" window.plugins.childBrowser.showWebPage('http://www.google.com');>click me</a>
Now, because I need to do it at runtime I've got this together:
$('a').on('click', function () {
window.plugins.childBrowser.showWebPage('http://www.google.com');
});
But the problem is that all links might have a different url so I need to somehow use the code about but with the link that it comes with and not a hardcoded url as above.
Links would initially look like below.
click me
How could I do this?
Use this.href
$('a').on('click', function () {
window.plugins.childBrowser.showWebPage(this.href);
return false;
});
Try this
$('a').on('click', function () {
window.plugins.childBrowser.showWebPage($(this).attr('href'));
});
On using Google I found that they are using onclick events in anchor tags.
In more option in google header part, it looks like normal a tag, but onclicking it doesn't get redirected but opened a menu. Normally when using
<a href='more.php' onclick='show_more_menu()'>More >>></a>
It usually goes to 'more.php' without firing show_more_menu(), but I have show a menu in that page itself. How to do like google?
If your onclick function returns false the default browser behaviour is cancelled. As such:
<a href='http://www.google.com' onclick='return check()'>check</a>
<script type='text/javascript'>
function check()
{
return false;
}
</script>
Either way, whether google does it or not isn't of much importance. It's cleaner to bind your onclick functions within javascript - this way you separate your HTML from other code.
You can even try below option:
More >>>
From what I understand you do not want to redirect when the link is clicked.
You can do:
<a href='javascript:;' onclick='show_more_menu();'>More ></a>
Use following code to show menu instead go to href addres
function show_more_menu(e) {
if( !confirm(`Go to ${e.target.href} ?`) ) e.preventDefault();
}
More >>>
One more solution that prevents default action even if the javascript function returns any value.
<a href="www.any-website.com" onclick='functionToRun();return false;'>
1) Link to work
<a href="#" onClick={this.setActiveTab}>
...View Full List
</a>
setActiveTab = (e) => {
e.preventDefault();
console.log(e.target);
}
I have a simple Javascript function which builds a Url that I want to provide a link to.
However, I can't seem to get the anchor tag working with it. How do I assign the href of the anchor tag the results of the Javascript function?
Neither one of these work correctly:
Click here
Click here
This is what I want to accomplish.
<script type="text/javascript">
function getUrl()
{
return "http://www.google.com";
}
</script>
Click here
-- update --
If I wanted to incorporate user278064s' comments, i would change the above into:
<script type="text/javascript">
function getUrl()
{
return "http://www.google.com";
}
</script>
Click here
None of the above solutions worked for me. A good way would be to create a new link in the function.
function fetchURL() {
var title = "Download";
var URL = title.link("https://www.google.com");
document.getElementById("dynamicButton").innerHTML = URL;
}
<body onload="fetchURL()">
<div id="dynamicButton">
//empty
</div>
<a onclick="getUrl();" href="#">Click here</a>
Click Here
Give the link an id:
<a id="specialLink">Click Here</a>
Later on, set its href from JavaScript:
document.getElementById('specialLink').href = getUrl();
(You might want to include a placeholder href in the link which people with JavaScript disabled will see.)
function getUrl(that) {
return "www.whateveryouwant.com";
}
// Point the a.href attribute at your url.
var a = document.getElementsByTagName('a')[0];
a.href = getUrl();
UPDATE
I assume that you want to use the getUrl() method to set the href attribute, because probably the pointed url is not static (so it could change at any moment e point to the getUrl() returned url.)
Anyway, you could assign the href attribute, when i.e. the user click on the link, in this way.
function changeHref(aElem) {
aElem.href = getUrl();
}
Following the complete code:
click me!
<script>
function getUrl(that) {
return "www.whateveryouwant.com";
}
function changeHref(aElem) {
aElem.href = getUrl();
}
</script>
One other thing. You should avoid the use of javascript: pseudo-protocol.
This fragment will explain you why:
A pseudo-protocol is a nonstandard take on this idea.
The javascript: pseudo-protocol is supposed to be used to invoke JavaScript from within a link.
Here’s how the javascript: pseudo-protocol would be used to call the popUp function:
Example
This will work just fine in browsers that understand the javascript: pseudo-protocol. Older browsers, however, will attempt to follow the link and fail. Even in browsers that understand the pseudoprotocol,
the link becomes useless if JavaScript has been disabled.
In short, using the javascript: pseudo-protocol is usually a very bad way of referencing JavaScript
from within your markup.
DOM Scripting: Web Design with JavaScript and the Document Object Model: Second Edition
The following worked for me
<script type="text/javascript">
$(function() {
document.getElementById("aTag").href = getUrl();
});
</script>
<a id="aTag">Click Here</a>