Ext.js - Open all external links in a new tabHow to make a link open in tabbed or new window without target attribute?Open a URL in a new tab (and not a new window) using JavaScriptProgrammatically open html link in new tabIs it possible to switch to previously opened tab instead of opening a new one?Open iFrame links in a new tab?href=“javascript:” open in new tabOpen specific link in new tab on pageloadWindow.open opening blank new tab?Sweetalert2: open external link in new tab on YesOpen and reload single tab on clicking a link opened in two different tabs
Who determines when road center lines are solid or dashed?
What is this green alien supposed to be on the American covers of the "Hitchhiker's Guide to the Galaxy"?
Why did my "seldom" get corrected?
Company looks for long-term employees, but I know I won't be interested in staying long
Why teach C using scanf without talking about command line arguments?
Why jet engines sound louder on the ground than inside the aircraft?
The most secure way to handle someone forgetting to verify their account?
How fast does a character need to move to be effectively invisible?
Strategy to pay off revolving debt while building reserve savings fund?
Why do space operations use "nominal" to mean "working correctly"?
How to interpret a promising preprint that was never published?
Is there a difference between PIO and GPIO pins?
Term “console” in game consoles
Is encryption still applied if you ignore the SSL certificate warning for self signed?
Amira L'Akum not on Shabbat
What happens if a company buys back all of its shares?
Finding all possible pairs of square numbers in an array
Is surviving this (blood loss) scenario possible?
How to remove the first colon ':' from a timestamp?
What are the basics of commands in Minecraft Java Edition?
Difference between c++14 and c++17 using: `*p++ = *p`
Round command argument before using
Practical example in using (homotopy) type theory
Why isn't a binary file shown as 0s and 1s?
Ext.js - Open all external links in a new tab
How to make a link open in tabbed or new window without target attribute?Open a URL in a new tab (and not a new window) using JavaScriptProgrammatically open html link in new tabIs it possible to switch to previously opened tab instead of opening a new one?Open iFrame links in a new tab?href=“javascript:” open in new tabOpen specific link in new tab on pageloadWindow.open opening blank new tab?Sweetalert2: open external link in new tab on YesOpen and reload single tab on clicking a link opened in two different tabs
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Maybe somebody has already faced with this problem.
I need to make all external links to open in a new browser tab.
The solution seems to be easy: just adding target="_blank"
to each link with external domain, but how can I implement it in a nice way, because whole app is written in Ext.js.
javascript extjs extjs4 extjs4.2
add a comment |
Maybe somebody has already faced with this problem.
I need to make all external links to open in a new browser tab.
The solution seems to be easy: just adding target="_blank"
to each link with external domain, but how can I implement it in a nice way, because whole app is written in Ext.js.
javascript extjs extjs4 extjs4.2
add a comment |
Maybe somebody has already faced with this problem.
I need to make all external links to open in a new browser tab.
The solution seems to be easy: just adding target="_blank"
to each link with external domain, but how can I implement it in a nice way, because whole app is written in Ext.js.
javascript extjs extjs4 extjs4.2
Maybe somebody has already faced with this problem.
I need to make all external links to open in a new browser tab.
The solution seems to be easy: just adding target="_blank"
to each link with external domain, but how can I implement it in a nice way, because whole app is written in Ext.js.
javascript extjs extjs4 extjs4.2
javascript extjs extjs4 extjs4.2
asked Mar 25 '14 at 8:22
Pavel TitenkovPavel Titenkov
731 gold badge2 silver badges7 bronze badges
731 gold badge2 silver badges7 bronze badges
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You change target attributes with JavaScript:
var tlinks = document.getElementsByTagName('a');
for (var i=0;i<tlinks.length;i++)
if (tlinks[i].href.indexOf('http://www.yourownurlhere.com') == -1)
tlinks[i].setAttribute('target', '_blank');
Remember to replace "yourownurlhere.com" with your actual url
add a comment |
The trick can be done with event delegation.
Ext.select('body').on('click', function (e, el)
el.target = '_blank';
, null, delegate: 'a');
Note that if you write just
Ext.select('a').on('click', function (e, el)
el.target = '_blank';
);
then you apply handler only to existing links. However, delegation also handles elements created afterwards. If you want such behaivor for links included only in certain container, you may change 'body' to any selector that matches that container.
Here is jsfiddle
add a comment |
I decided to answer my own question, because maybe it will be useful for anybody.
The only way to catch all clicks on the links is to control body clicks (as triclozan wrote in his answer).
This code will modify every link after clicking and will open it in the new window:
Ext.getBody().addListener('click', function (event, el)
var clickTarget = event.target;
if (clickTarget.href && clickTarget.href.indexOf(window.location.origin) === -1)
clickTarget.target = "_blank";
);
Hope this code will save few hours of googling for somebody with the same problem :)
add a comment |
You can simply do :
window.open("Your link");
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22628871%2fext-js-open-all-external-links-in-a-new-tab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You change target attributes with JavaScript:
var tlinks = document.getElementsByTagName('a');
for (var i=0;i<tlinks.length;i++)
if (tlinks[i].href.indexOf('http://www.yourownurlhere.com') == -1)
tlinks[i].setAttribute('target', '_blank');
Remember to replace "yourownurlhere.com" with your actual url
add a comment |
You change target attributes with JavaScript:
var tlinks = document.getElementsByTagName('a');
for (var i=0;i<tlinks.length;i++)
if (tlinks[i].href.indexOf('http://www.yourownurlhere.com') == -1)
tlinks[i].setAttribute('target', '_blank');
Remember to replace "yourownurlhere.com" with your actual url
add a comment |
You change target attributes with JavaScript:
var tlinks = document.getElementsByTagName('a');
for (var i=0;i<tlinks.length;i++)
if (tlinks[i].href.indexOf('http://www.yourownurlhere.com') == -1)
tlinks[i].setAttribute('target', '_blank');
Remember to replace "yourownurlhere.com" with your actual url
You change target attributes with JavaScript:
var tlinks = document.getElementsByTagName('a');
for (var i=0;i<tlinks.length;i++)
if (tlinks[i].href.indexOf('http://www.yourownurlhere.com') == -1)
tlinks[i].setAttribute('target', '_blank');
Remember to replace "yourownurlhere.com" with your actual url
answered Mar 25 '14 at 10:11
NillervisionNillervision
3911 silver badge10 bronze badges
3911 silver badge10 bronze badges
add a comment |
add a comment |
The trick can be done with event delegation.
Ext.select('body').on('click', function (e, el)
el.target = '_blank';
, null, delegate: 'a');
Note that if you write just
Ext.select('a').on('click', function (e, el)
el.target = '_blank';
);
then you apply handler only to existing links. However, delegation also handles elements created afterwards. If you want such behaivor for links included only in certain container, you may change 'body' to any selector that matches that container.
Here is jsfiddle
add a comment |
The trick can be done with event delegation.
Ext.select('body').on('click', function (e, el)
el.target = '_blank';
, null, delegate: 'a');
Note that if you write just
Ext.select('a').on('click', function (e, el)
el.target = '_blank';
);
then you apply handler only to existing links. However, delegation also handles elements created afterwards. If you want such behaivor for links included only in certain container, you may change 'body' to any selector that matches that container.
Here is jsfiddle
add a comment |
The trick can be done with event delegation.
Ext.select('body').on('click', function (e, el)
el.target = '_blank';
, null, delegate: 'a');
Note that if you write just
Ext.select('a').on('click', function (e, el)
el.target = '_blank';
);
then you apply handler only to existing links. However, delegation also handles elements created afterwards. If you want such behaivor for links included only in certain container, you may change 'body' to any selector that matches that container.
Here is jsfiddle
The trick can be done with event delegation.
Ext.select('body').on('click', function (e, el)
el.target = '_blank';
, null, delegate: 'a');
Note that if you write just
Ext.select('a').on('click', function (e, el)
el.target = '_blank';
);
then you apply handler only to existing links. However, delegation also handles elements created afterwards. If you want such behaivor for links included only in certain container, you may change 'body' to any selector that matches that container.
Here is jsfiddle
answered Mar 25 '14 at 16:30
triclozantriclozan
2281 silver badge7 bronze badges
2281 silver badge7 bronze badges
add a comment |
add a comment |
I decided to answer my own question, because maybe it will be useful for anybody.
The only way to catch all clicks on the links is to control body clicks (as triclozan wrote in his answer).
This code will modify every link after clicking and will open it in the new window:
Ext.getBody().addListener('click', function (event, el)
var clickTarget = event.target;
if (clickTarget.href && clickTarget.href.indexOf(window.location.origin) === -1)
clickTarget.target = "_blank";
);
Hope this code will save few hours of googling for somebody with the same problem :)
add a comment |
I decided to answer my own question, because maybe it will be useful for anybody.
The only way to catch all clicks on the links is to control body clicks (as triclozan wrote in his answer).
This code will modify every link after clicking and will open it in the new window:
Ext.getBody().addListener('click', function (event, el)
var clickTarget = event.target;
if (clickTarget.href && clickTarget.href.indexOf(window.location.origin) === -1)
clickTarget.target = "_blank";
);
Hope this code will save few hours of googling for somebody with the same problem :)
add a comment |
I decided to answer my own question, because maybe it will be useful for anybody.
The only way to catch all clicks on the links is to control body clicks (as triclozan wrote in his answer).
This code will modify every link after clicking and will open it in the new window:
Ext.getBody().addListener('click', function (event, el)
var clickTarget = event.target;
if (clickTarget.href && clickTarget.href.indexOf(window.location.origin) === -1)
clickTarget.target = "_blank";
);
Hope this code will save few hours of googling for somebody with the same problem :)
I decided to answer my own question, because maybe it will be useful for anybody.
The only way to catch all clicks on the links is to control body clicks (as triclozan wrote in his answer).
This code will modify every link after clicking and will open it in the new window:
Ext.getBody().addListener('click', function (event, el)
var clickTarget = event.target;
if (clickTarget.href && clickTarget.href.indexOf(window.location.origin) === -1)
clickTarget.target = "_blank";
);
Hope this code will save few hours of googling for somebody with the same problem :)
answered Mar 28 '14 at 10:11
Pavel TitenkovPavel Titenkov
731 gold badge2 silver badges7 bronze badges
731 gold badge2 silver badges7 bronze badges
add a comment |
add a comment |
You can simply do :
window.open("Your link");
add a comment |
You can simply do :
window.open("Your link");
add a comment |
You can simply do :
window.open("Your link");
You can simply do :
window.open("Your link");
answered Mar 26 at 10:01
baidehi ghoshbaidehi ghosh
11 bronze badge
11 bronze badge
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22628871%2fext-js-open-all-external-links-in-a-new-tab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown