Extracting page title using javascript

后端 未结 2 1391
礼貌的吻别
礼貌的吻别 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(/]+?\/>|/gi, '');
        }
        catch {
        dataString = data.results[0];
    
    }
        // Fake XHR callback.
        _success.call(this, {
        responseText: dataString
        }, 'success');
           }
        }
    

提交回复
热议问题