Is it possible to intercept all redirects and open the contents in a new window / pop up?

So, I have a page containing an iframe. Inside the iframe there are links that open a new page in the same window (self.location.href) (window.open (urlstring, 'false'), etc. Etc ....

Is there a way to make all links inside this window open their contents in a new window / pop up? Overrides its redirection settings and doesn't change the code inside the iframe?

The reason I'm asking about this is because, in my opinion, the iframe page still refers to the parent window as its window, so when a function like "window.self.open" was run, it took all my parent window away ...

Maybe in any case, embed the iframe in a separate window inside the page? Just not sure how to avoid the same link window ...

Thanks!

+6
source share
2 answers

You can set the links to open in a new window by adding target="_blank" to the a element (for example, <a href="example.html" target="_blank">Example</a> ).

If you want this to apply to all links without touching the links themselves, you can enable the jquery function to do this for you:

 $("a").attr("target","_blank"); 
+1
source

You can also add the target attribute in the base -tag in the header.

 <base target="_blank"> 

This will apply to all links.

0
source

Source: https://habr.com/ru/post/920714/


All Articles