Extracting page title using javascript

后端 未结 2 1360
礼貌的吻别
礼貌的吻别 2021-01-17 04:38

I\'m trying to extract the page title of an external site by using a url.

You know how \"document.title\" returns the title of the page the JS is running on? I was w

相关标签:
2条回答
  • 2021-01-17 04:59

    I think you're looking for $.ajax, since this is a cross domain request, which can be done from js using a call to YQL:

    http://usejquery.com/posts/the-jquery-cross-domain-ajax-guide

    EDIT

    Okay I finally got a working example: http://jsfiddle.net/zXVcy/

    EDIT

    Here is how to fix the script tag problem in xdomain.js:

       if (_success) {
        var dataString = "";
        try { 
        dataString = data.results[0].replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '');
        }
        catch {
        dataString = data.results[0];
    
    }
        // Fake XHR callback.
        _success.call(this, {
        responseText: dataString
        }, 'success');
           }
        }
    
    0 讨论(0)
  • 2021-01-17 05:03

    That is not possible through Javascript. You must use a server script to achieve this.

    0 讨论(0)
提交回复
热议问题