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
Related
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
I am using Mozilla Firefox and I am trying to figure out a way to access the content of other tabs in the same window using JavaScript and the DOM (I am open to other techniques if exist).
E.g., I want to run JavaScript code in tab1 which can find the title of some other tab. Basically I need this so that I can identify a tab which has opened due an href in my current page without using window.open method. All I want is a simple hyperlink which opens a page belonging to the same domain as the current page (the page should be opened in a new tab). Now I want to be able to access this new tab from the current tab.
Whilst you can easily open a new window using JavaScript, I'm sure that is as far as it goes. From a security point of view you wouldn't want JavaScript in one tab being able to query / access the DOM in another tab. Any site would then be able to gain access to your bank account details, etc. if both sites were opened in separate tabs.
You can access the new window/tab if it was opened with JavaScript and the page indeed is in the same domain.
You can open the window/tab like so
var win = window.open("/path_to_page");
Then you'll have to wait for the page to load before you can access e.g. the title.
win.onload = function(){ alert(win.document.title); };
You could use HTML5 cross-window messaging (archive.org link...but that's kind of cutting edge.
Even in that case, you'd probably need to hijack the <a> tag 'click' event with JavaScript and open the window yourself so that you'd have access to the new window object for posting messages.
Try setting a cookie which is accessible to any page in the same domain. On other pages, use a JavaScript timer to check if the cookie value has changed and when it has you can use its value and take an action.
It worked for me.
Well, this would not be possible, you could try
<a target="_blank" rel="opener" href="about:blank"></a>
This makes a link that opens an about:blank, this will have the same domain as the page that opened It because of the Same-Origen-policy.
I changed a domain name of my website, and now every link opens in new tab (menu, logo, external links etc.) I want to know how to get back to normal behavior when Joomla opens only external links in new window. How can I solve this and what could be the cause of it?
Link to my website: http://sparkle-soft.com
I'm using Joomla 2.5
You have a inline script tag in your head for some sort of specialtrack. There is a line of code within the function that is applying a blank target attribute to all links on your page:
links[i].setAttribute('target', '_blank');
Check to see what tracking you have added to your site, look for any options if provided that would allow you to change this. It could be coming from an extension or your template but hard to tell as it's inline, rather than a source file.
I have a JavaScript application in a tab which opens if I click on a certain link on my page. If I click on the link again, I need to check if that tab is allready opened - if it is, then switch to that tab and do something, otherwise open a new tab.
Unfortunately using
var myApp = window.open("http://www.mypage.com/myapp.html", "My App");
if(myApp){
won't help me, because I can't rely on the URL, due to the fact that the URL will differ on each environment that I'm using.
How can I achieve this if I can't rely on the URL? The only thing I can check is the tab's name - it will allways be the same. How can I access the browser's tab array, please?
Thanks!
As far as I understand, you cannot access the browser's tab array (certainly not through JavaScript). This would be a security breach on the client side. You should think of each browser tab as a browser instance of it's own - unaware of any other tab.
You can track that if tab is opened already using the Cookie/Local storage.
Save the value "isOpened=true" in either Cookie or localStorage and Be sure to delete the values from the same when that tab is Closed or when user navigates to other pages using "onunload" event.
But the page you are going to open should be on the same Domain for accessing/ setting the Cookie.
Still we cannot do anything if the user opens the page by just copying the link.
as you are opening new window using javascript you can do this you can add a dummy attribute say "data-isOpend='no'" on that element
and when user click on that element you can change that attribute to "data-isOpened='yes'"and in javascript function before opening tha new window you have to check if data-isOpend=='no' then open link in new window else do nothing
(Just leaving a differenct ans here if any other dev comes here looking for solution for such prob,Just like me :) )
We can assign name to the tab while creating it
For eg.
function view_preview()
{
var abc;
if(abc!=null){
abc.close();
}
var url=some_link
abc=window.open(url,'tab_name');
}
Here, we are opening a new tab and if that tab is already opened we are 'refreshing' it.
I am using Mozilla Firefox and I am trying to figure out a way to access the content of other tabs in the same window using JavaScript and the DOM (I am open to other techniques if exist).
E.g., I want to run JavaScript code in tab1 which can find the title of some other tab. Basically I need this so that I can identify a tab which has opened due an href in my current page without using window.open method. All I want is a simple hyperlink which opens a page belonging to the same domain as the current page (the page should be opened in a new tab). Now I want to be able to access this new tab from the current tab.
Whilst you can easily open a new window using JavaScript, I'm sure that is as far as it goes. From a security point of view you wouldn't want JavaScript in one tab being able to query / access the DOM in another tab. Any site would then be able to gain access to your bank account details, etc. if both sites were opened in separate tabs.
You can access the new window/tab if it was opened with JavaScript and the page indeed is in the same domain.
You can open the window/tab like so
var win = window.open("/path_to_page");
Then you'll have to wait for the page to load before you can access e.g. the title.
win.onload = function(){ alert(win.document.title); };
You could use HTML5 cross-window messaging (archive.org link...but that's kind of cutting edge.
Even in that case, you'd probably need to hijack the <a> tag 'click' event with JavaScript and open the window yourself so that you'd have access to the new window object for posting messages.
Try setting a cookie which is accessible to any page in the same domain. On other pages, use a JavaScript timer to check if the cookie value has changed and when it has you can use its value and take an action.
It worked for me.
Well, this would not be possible, you could try
<a target="_blank" rel="opener" href="about:blank"></a>
This makes a link that opens an about:blank, this will have the same domain as the page that opened It because of the Same-Origen-policy.