Preventing pages being open in a new tab/window

前端 未结 3 515
悲&欢浪女
悲&欢浪女 2020-12-31 15:19

I am working on a project that behaves very strange when the user open pages in a new tab or in a new window, causing the app to crash.

I need some javascript that

3条回答
  •  长情又很酷
    2020-12-31 15:19

    Replace all < a > tags attribute to _self, that will force the broswer to open the hyperlink in a new tab

    Array.prototype.forEach.call(document.getElementsByTagName('a'), function(el, i){
    if(el.target=="_blank"){ el.target="_self" }
    });
    

提交回复
热议问题