LoginSignup
1
7

More than 5 years have passed since last update.

他のページのHTMLを取得する方法

Last updated at Posted at 2016-10-27

> 他のページのHTMLを取得する方法

クロスドメインで他のページを取得する方法

Ajaxで取得したHTMLからタイトルを取得する方法

index.html

<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="utf-8">
        <title>Get A Other Page</title>
    </head>
    <body>
        <script src="js/jquery.js"></script>
        <script src="index.js"></script>
    </body>
</html>

index.js

$.ajax({
    type: 'GET',
    // 取得したいページのアドレス
    url: 'http://localhost/',
    success: function(data) {
        console.log(data);
    }
});

取得したページ

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Taiyaki Web</title>
    ...
  </head>
  <body>
    ...
  </body>
</html>
1
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
7