Is it possible to execute any javascript on a page without manually adding it to the page?

The situation is this: there is a A.aspx page that has a hyperlink to another B.aspx page. I want to run javascript after someone clicks on the hyperlink in A.aspx and after loading B.aspx. But I do not want to manually add this javascript to B.aspx?

The background for this is as follows: In the sharepoint site collection, all pages use a master page, but there may be separate pages that are offline and they do not use a master page. The challenge is to add javascript to every page of the site (both standalone and regular). So I added this javascript to the main page, but since these offline pages do not use the main page, they do not load javascript. The situation is that some regular sharepoint pages have hyperlinks pointing to these offline pages, so when someone clicks on the hyperlink on a regular sharepoint page, the offline page loads. Since there are quite a few offline pages, and I don’t want to touch them, I thinkwhat if they are loaded (if the user clicks a hyperlink on a regular sharepoint, if there is any way to execute javascript on these pages page)?

+4
source share
1 answer

I want to run javascript after someone clicks on a hyperlink in A.aspx and after loading B.aspx, but I do not want to manually add this javascript to B.aspx

You cannot do this, no. (Not without everyone having the browser extension installed.) I’m afraid it’s unpleasant if the offline pages do not already have the script that they load so that you can add this new code, you will have to change each of the offline pages to include a new script.

I checked just now - hyperlinks look like this <a href="javascript:void(0);" onclick="OpenPopUpPage('B.aspx?ItemID=65','',500,350);">test link</a>, they seem to useOpenPopUpPage

. OpenPopUpPage window.open, A.aspx , B.aspx , , A.aspx B.aspx ( , , ).

OpenPopUpPage window.open, (DOMContentLoaded , , load)), :

var url = "B.aspx";
var wnd = window.open(url);
checkChildReady();
function checkChildReady() {
    if (wnd.document && String(wnd.document.location).indexOf(url) != -1) {
        if (wnd.document.readyState != "loading") {
            windowReady();
        } else {
            wnd.document.addEventListener("DOMContentLoaded", childReady, false);
        }
    }
}
function childReady() {
    // Do your stuff here
}
+1

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


All Articles