Get script file outside of vue2 scope

76 views Asked by At

I need to detect if adblocker is being used on my site, from googling around the most common method of checking this is to create a ads.js or adverts.js file and then display a message if that has been blocked.

This file has been set up however I am having trouble accessing this file when it needs to be outside of the vue scope in a vue componenet, any suggestions?

1

There are 1 answers

0
Suresh Velusamy On

You might need to register independent js file's to the window object, then inside your component, you can call the object or function. For example, if your ads.js contain like as follow snippet

function block(){
 // console.log('i am gonnna show this ')
}

In your vue component

var newData = new Vue({

    el: '#app',
    data: {
        demo:'',         
    },

    methods: {
        fetchData: function (data) {
            window.block()
        }
    },
    created: function () {
         window.block()
    }

})

Like above the code you can achieve.