如何获得加载html页面的页面路径

How to get the page path which is loading a html page?

本文关键字:路径 html 何获得 加载      更新时间:2023-09-26

我有一个页面app/BlockA/page1.html,因为我正在加载另一个页面

。e $("#div1").load("app/Common/sample.html").

app/BlockB/page2.html相同

此子页面已成功从两个页面加载,

现在加载sample.html基于父页面即BlockA/page1.html或BlockB/page2.html我有一个自定义的功能。

如何确定从哪个页面我的子页面加载??

。e我想获得父页面url,即绝对路径,如BlockA/page1.html or BlockB/page2.html

注意:使用window. location .href给出url即http://localhost:5012/masterpage.hmtl,这是我不想要的。这是一个单页应用程序

您可以使用window.location.href获取父页面的URL。

您可以查看窗口。定位并根据返回的结果创建功能。

$(function(){
    var loc = window.location.href;
    if(loc.indexOf('page1') > 0) {
        // do stuff
    }
    else { //do other things or check for other pages
    }
});

如果我理解正确使用document.referrer