Reputation:
How to control the redirection without modifying the HTML code
The content of the page is returned Webservice and all the URLs are redirected to other tabs, and I have no control over HTML
Is there a way to force all redirects in the same page?
Upvotes: 0
Views: 51
Reputation: 4885
You can get all the anchors of the website and add a target
property with the value _blank
.
Specifies where to display the linked URL. It is a name of, or keyword for, a browsing context: a tab, window, or <iframe>
. The following keywords have special meanings:
_self
: Load the URL into the same browsing context as the current one. This is the default behavior._blank
: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead._parent
: Load the URL into the parent browsing context of the current one. If there is no parent, this behaves the same way as _self
._top
: Load the URL into the top-level browsing context (that is, the "highest" browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this behaves the same way as _self
.(function($) {
$('a').each(function(idx, element) {
element.target = '_blank';
});
})(jQuery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href='https://google.pt/'>Google</a>
<a href='https://stackoverflow.com'>Stack Overflow</a>
Upvotes: 1