Catch the window.open from javascript

前端 未结 3 480
自闭症患者
自闭症患者 2021-01-21 15:05

I have a web page into a html iframe, the web page has a javascript function to open links, that function use the window.open method to open a new window.

I cannot modif

3条回答
  •  花落未央
    2021-01-21 15:19

    I'll assume the 'mapguide' content is served from a different domain than the page containing the iframe.

    If that's the case, you'd need to "proxy" the 'mapguide' content -- i.e: your iframe will need to load the mapguide content from another script URL (I'll assume PHP for this example) on your server, whose code would fetch the 'mapguide' software from wherever it really comes from. This part is easy, and the server-side code might look like this:

    
    

    The iframe src attribute should point at the PHP file on your server which contains that code (instead of the 'mapguide' server).

    If the 'mapguide' content contains HTML links, loads CSS/JavaScript files, or does AJAX calls, then you'll need to have your server-side code rewrite those URLs to refer back to your server. That part is not very easy, and really depends on how complicated the 'mapguide' JavaScript is.

    So after the comment above that says alter content here, you'd need to do some awful regexp replacements on (or parse and re-generate) the HTML contained in $content, with the goal of changing every single URL to pass through your "proxy" PHP script and be loaded from the appropriate place on the 'mapguide' server.

    If you manage to pull all of that off, then your iframe will be server from the same domain as your containing HTML page and so the outer page's JavaScript will be able to replace the window.open function of the iframe -- to prevent the popup, or do whatever you want instead -- as @jbabey says in another answer.

    All of this presumes that the 'mapguide' content doesn't come with a user agreement and/or copyright policy which forbids "scraping" (automatically copying) their (the 'mapguide' content's authors') content.

提交回复
热议问题