I have a table whose current value is stored in localStorage (see JSfiddle). How do I set up a link in <a href> to open the desired table, e.g. second in order?
For example: I'm on the Home page and clicking <a href> redirects me to the List page, where tab Teacher is opened, and this option is also saved to localStorage (that is, when the List page is refreshed, the Teacher tab remains open).
Thank you!
If I understand correctly, you want to create a link to an HTML page, which, on that page, there are various options for a current tab to be selected, and you want, that when someone clicks on a particular link, that tab will already be open.
Am I right?
If so, then let's do the following.
If you're setting the value when the page loads based on localStorage, then by definition it will only open that which was opened last.
So the question is how do you make the particular link open only one tab, and another link open the other? It seems from your example that you want a link to the "student" tab and a separate link to the "teacher" tab.
To do this just with client side JavaScript, you can use the window location hash, and read it with JavaScript, and do the respective function based on the hash value.
Say you have some URL like example.com, which brings you to a default tab. Then, if you want a link to a non default tab, simply add something to the end of the URL preceded by a "#" symbol, then you can read it in JavaScript with location.hash
So the new URL may look like: example.com/#teacher, then somewhere in your page with JavaScript, do:
var page = location.hash //== "#teacher"
activateTab(page.replace("#", "")); //activates "teacher" tab, assuming that function would do something, but you get the idea
Related
So I have a page that is navagated through by clicking on tabs that change what is displayed in the body of the website, and when you go to a new tab (in the site) it changes the url. e.g I'm in the home tab, and the url is changed to https://a.website.com/home, then i go to the changelog tab, and the url is changed to https://a.website.com/changelog. niiether of these urls actually exist, so how would I make it so when the user reloads they are directed to https://a.website.com, not to a page not found error page?
possibly using window.onbeforeunload?
Mark the tab that is being used as a parameter of the page:
https://a.website.com?tab=home
https://a.website.com?tab=changelog
Then, on your page you can decide which tab to show.
I have a series of html pages that include a link to an informational page. In the menu for that page, I have a link back to the referring page that uses this code:
<a class="nav_link" onclick="location.href = document.referrer;" onmouseover="this.style.cursor='pointer'">Return to Text</a>
It works as expected on the first use, but if someone moves to another page and then clicks on the link to return back, it will sometimes take them to the old referring page. So, for example, if someone went to from page 1 to my referring page, returned via the link this anchor tag generates, and then went to page 3 and clicked on the link to the informational page, upon clicking on "Return to Text" for a second time they might go back to page 1 rather than page 3, as expected.
I'm assuming that the issue is that document.referrer is being stored in memory and is not being overwritten when the user clicked on the link to go to the informational page a second time. Why is this, and is there a way for me to either make sure the memory is always cleared when they click on the link to return or create a more robust version of the location.href = document.referrer; onclick?
If you want a "back link," you're better off with history.go(-1):
onclick="history.go(-1);"
That actually emulates the back button, rather than adding a new entry to the history with a repeat of the previous URL.
Ok, I do not have code for this so I would need assistance here. I have a page that has multiple tabs worth of information. If I proceed to an entirely new page (URL) and then hit back on the browser, is there a way to land back on the tab I left off of?
when you click on a tab you can append a url parameter e.g. ?tab=tab1. And when you load the page you can check you're url parameters and default to that tab if it is in the parameter.
Here's an example that's similar. When you click on the toolbar on the left on bootstrap's getting started page it appends that item to the url. so when i click on 'support' the url looks like http://getbootstrap.com/getting-started/#support and when you go to that url it automatically scrolls you to that section on the page.
Have multiple hyperlinks in a report, everytime a click on a hyperlink the webpage opens in a new tab,
Is it possible to open the hyperlinks in only one tab instead of multiple tabs using javascript ?
Please help
I am currently using window.open to open the webpages, I cannot use target. Below is the code :
I basically have a jqgrid where all the values of a column have hyperlink,
if (GridColNum == 2) //index of the column
{
localStorage.valuekey = $('#filters_grid').jqGrid('getCell', GridRowId, 1);
window.open('http://mywebpage.html');
}
And i am using the clicked value in another page using localstorage feature
Yes, it's possible. Use syntax
<a href="..." target="rptTab"/>
for all relevant links. This way the first time a link is clicked a new tab will be opened; for subsequent clicks, that tab will be reused.
EDIT: if you're opening the link in javascript using window.open, then you need to specify the name of the tab/window as the second parameter:
window.open('http://mywebpage.html', 'rptTab');
You probably have a target='_blank' attribute in your links. Just remove them. If that does not help please post some code so we can see what is happening
When you specify the target of a window.open() call or an tag, you can specify _blank, _parent, _self or _top, as special tab/window names. Alternatively you can specify a new tab/window name, when you specify this tab/window another time, it will refer to the original one that you opened.
hyperlinks opens a new browser tab - is due to
target='_blank'
attribute of it. you can remove it using following jQuery code.
$('a').removeAttr('target');
now on-wards every link will get open in the same page.
You don't need javascript for this. Just use the target-attribute of the a tag. All links with the same target should be opened in the same tab.
http://www.w3schools.com/tags/att_a_target.asp
I have made tabs on my site. By tabs I mean the navigation links, rather then loading a new page use some java script and css to just switch to another tab containing more content. I'm wondering how I would be able to link to a specific page when it's done like this?
My code is similar to this one:
Using jquery easyui, how to create a tab by a link which is in a tab?
Edit: http://fogest.net16.net/righttoweb/ <<< There is a link to the site. Look at the tabs. How would I link to the page of one of those tabs?
Add anchors to the end of your URL, ie http://URL/righttoweb#about and on $(document).ready() block of code pick up the anchor and using a hash table figure out what tab needs to be selected.
Also make sure when users click on your tabs, you update the anchor in the top bar as well, in order to preserve which tab was selected if the user decides to bookmark the URL or send it to someone else
edit:
Well every time a user clicks on one of your tabs, with the onClick event you need to alter the navigation history of your page, for ex:
window.history.pushState("object or string", "Some Title", "#tab" + tabname);
This will enable the back/forward buttons to work
then everytime the page loads you need to
$(document).ready(function() {
if(window.location.href.indexOf('#'))
updateTab(location.hash);
});
function updateTab(tabname) {
your logic to update tab...
}
Hope this makes sense