简体   繁体   中英

How do I load an image from another page using HTML?

I read that you can load an image from another page with the load method.

For example: $("#result").load(url, 'tag.attribute')

However I need to get the path of the first image from a list on another page and put it in an <img> tag of my code to show it. I am not able to do it using jQuery (the CDN is in index.html ). How can this my code below work? Can you do this with pure JavaScript to use with React?

import React, {Component} from 'react'

/* global $ */

class GetImage extends Component {
state = {
    loaded: false
}
image = () => {

    const url = 'https://www.google.com/search?q=exemple&source=lnms&tbm=isch&sa=X&ved=0ahUKEwin8pXtzu3fAhXKlZAKHQ3dBAcQ_AUIDigB&biw=1536&bih=558'
    $("#content").load(url, 'div.data-ri===0.img.src')
    this.setState({loaded: true})

}
render(){
    return (
        <div>
            {this.state.loaded && <img id='content'></img>}
            <button type='button' onClick={this.image}></button>
        </div>
    )
}
}

您为什么不只是从另一个网站复制img链接,然后将其放入您网站上的img src =“”?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM