I'm using a plugin on my site to enable quiz functionality. When a lesson/quiz has been completed by a user there is a popup that features a button with a link back to another page. The problem I have is that I need to change this link.
This is what console looks like:
View Console
I need to be able to edit the href link shown here so that I can redirect users to the correct page. Firstly I need to know if this is possible and secondly how I could go about implementing this change.
I'm presuming it can be achieved with JS, but my knowledge of JS is limited so I'm unsure about the execution.
You can change attribute href as simple as any other attribute:
$('a.gdlr-lms-button').attr('href', 'new-url');
With jquery you can do it like this.
Where test the classname is so just replace that by gdlr-lms-button
$('a.test').attr('href', 'www.google.be');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class='test' href="www.facebook.com">Hello</a>
Related
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()
I have an invoice system made in PHP. There is a view with all customer's invoices. I'd like to make an option to print an invoice.
I know about window.print() and media="print" for CSS. But I was thinking, is it possible to just print an invoice by clicking a button next to it, but staying on the list page? It would just open a printing prompt with different content and do nothing to the current experience.
I thought of a workaround. On click, I could just replace contents of some element with invoice's data and make the styles hide everything else besides that container. That looks like a trick to me though. Is there any other solution to that problem? Perhaps something like download attribute for links:
Download Me
That could be something like:
<a href="invoice.php?id=3" print>Print Me</a>
Or perhaps an HTTP header? Please share some advices.
I would suggest to use JQuery PrintJS plugin below:
http://printjs.crabbly.com/
This will ultimately solve your problem.
We are working on a Bootstrap website to present our schoolwork. I have a fair understanding of the used html code, but I am having one problem.
To link to a specific tab/section within a page this link is used:
href="#tab"
I have copied the original index.html and thus created a second webpage. I'm able to link to this page using:
href="page2.html"
But I'm not able to link directly to a tab/section on that second page. I tried using href="page2.html/#tab" or "page2.html#tab" etc. But it doesn't work yet, I think I miss some fundamental knowledge about this coding.
Could anyone explain me how to get this working, in 'normal' language. There are several (older) solutions, but can't get them to work in the javascript files.
This should help...
http://codepen.io/mattsince87/pen/exByn
LINK -> <a id="link1" class="nav-section1" href="#section1">S1. Info</a>
Content -> <h1 id="section1">1. Info</h1>
You can use something like this as i have this thing running in my project. these will check the page if it contains the tabs then it will take the last value from the url of the page2 and will make it visible.
if($("#tabs").length)
{
var id = window.location.hash.substr(1);
$('#tabs a[href="#'+id+'"]').tab('show');
}
In facebook fan page tab application I click tab button and like to go to the specific
portion of the fan page content without pixel calculation.
For example to point the comment box.
for that purpose url http://www.facebook.com/pages/AAAA/4444444?sk=app_UUUU8&app_data=php
and
<div id="php"><textarea name="a"></textarea></div>
is in body
but I would like to achieve that goal automatically using Javascript?
will this do?
link
You could always style the link as a button, if you must.
Simply, Connect is enough to do that instead.
<button onclick="document.getElementById("php").scrollIntoView()">Go</button>
or
<button onclick="document.getElementById(location.hash.substring(1)).scrollIntoView()">Go</button>
is a javascript alternative to using the anchor
try the following code on click of the button
window.location.href="#php";
You can go to any part of the body using the above code and providing the id of the content you wish to go....
I'm looking to dynamically change the flash files based from an hyperlink on the page without the page having to reloading. Is this possible through javascript?
Yes, it's possible. See this tutorial:
http://learnswfobject.com/advanced-topics/load-a-swf-using-javascript-onclick-event/
Do you mean you want to change the destination of a hyperlink on the page through javascript? Something like this should do that:
<body>
<a id="test" href="http://www.google.com">Go to Google</a>
<input type="button" onclick="document.getElementById('test').href = 'http://www.yahoo.com'" value="Go to Yahoo"/>
</body>
Or are you trying to do something different? Like changing what Flash is displayed by clicking a hyperlink? Haven't tried it, but the above approach might work there, too, with a little tweaking. Remember that the attributes of an element (like the href above) are available in javascript as properties once you have a reference to the element, so you should be able to change whatever attribute of the element you need to.