Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

content of a .json file

Status
Not open for further replies.
Hi

Actually the "get the content" part has little to do with JSON or other content type.
HTML:
[b]<html>[/b]
[b]<head>[/b]
[b]<script>[/b]
[COLOR=orange]addEventListener[/color][teal]([/teal][i][green]'load'[/green][/i][teal], () => {[/teal]
    [gray]// get the iframe's content[/gray]
    [b]var[/b] jsonText [teal]=[/teal] document[teal].[/teal][COLOR=orange]getElementById[/color][teal]([/teal][i][green]'source'[/green][/i][teal]).[/teal]contentDocument[teal].[/teal]body[teal].[/teal]textContent
    [gray]// and use it for something, but still as string[/gray]
    document[teal].[/teal][COLOR=orange]getElementById[/color][teal]([/teal][i][green]'destination'[/green][/i][teal]).[/teal]value [teal]=[/teal] jsonText

    [gray]// now log it to console as JavaScript object[/gray]
    console[teal].[/teal][COLOR=orange]log[/color][teal]([/teal][i][green]'JSON copied from iframe to textarea is :'[/green][/i][teal],[/teal] JSON[teal].[/teal][COLOR=orange]parse[/color][teal]([/teal]jsonText[teal]))[/teal]
[teal]})[/teal]
[b]</script>[/b]
[b]</head>[/b]
[b]<body>[/b]
JSON in iframe :[b]<br><iframe[/b] [maroon]src[/maroon][teal]=[/teal][i][green]"peterpann.json"[/green][/i] [maroon]id[/maroon][teal]=[/teal][i][green]"source"[/green][/i][b]></iframe>[/b]
[b]<hr>[/b]
JSON in textarea :[b]<br><textarea[/b] [maroon]id[/maroon][teal]=[/teal][i][green]"destination"[/green][/i][b]></textarea>[/b]
[b]</body>[/b]
[b]</html>[/b]

Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top