簡體   English   中英

我們如何在 react.js 中獲取 iframe 當前 url

[英]How can we get iframe current url in react.js

我正在創建一個簡單的反應應用程序。 在反應組件中,我使用的是 Iframe。 現在我想從 iframe 訪問當前的 URL。 當用戶單擊網站頁面鏈接時,它會轉到另一個頁面,並且 URL 會發生變化。 如何訪問當前的 URL? 我的代碼如下:在 App.Js 文件中

<IframeComponent src="http://scratchpads.org/" height="100%" width="45%"/>

它是組件代碼:

 import React from 'react';
export default class IframeComponent extends React.Component {
    myOnloadFunction = () =>{
    console.log(this.props.src)
   // document.getElementById('frame').src =  "http://scratchpads.org/"
    console.log(document.getElementById('frame').src)
//    console.log(document.frames['frame'].document.location)
    }
  render() {  
    return (
      <div>
        <iframe src={this.props.src} height={this.props.height} width={this.props.width}  className="fullheight" onLoad={this.myOnloadFunction} id = "frame"  /> 
      </div>
        )}}

您要達到的目的是禁止的,如果 iframe url 不同,則無法更改,也無法訪問父網站數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM