简体   繁体   中英

HTML Passing Values between pages in different locations

I am needing to open an html page on server-A and grab some values from server-B's webpage. In other words I want to display server-B's webpage values on server-A's webpage.

The webpage (server-B) data I need the values from is being populated by a source that I do not have access. The values are written into what appears to be a variable that looks like this: [[0]]. When the page is accessed that value [[0]] is populated with current data.

I have unsuccessfully tried to attach a label to the [[0]] to allow reading from server-A with a form post and get methods.

What should my approach be to move this data in [[0]] to server-A webpage?

Server-B page:

<html>
<!-- Head information for the page including page title -->

<head>
  <title>Test</title>
</head>

<body color=#FFFFFF>
  <!-- Start of your page body -->
  <!-- This code displays the current tag value for index 0
    [[0]] will be replaced by the tag value a the time the page is loaded -->
  The value of the tag with index 0 is [[0]]
  <!-- Added code to store [[0]] in div -->
  <div class="pink-box" id="thatDiv">[[0]]</div>
</body>

</html>

I added this html/javascript for Server-A and I am getting the an error described with COR:

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Get Div</title>
  <style>
    body {
      font-size: 12px;
      font-family: Arial;
    }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>

<body>
  <b>Div:</b>
  <ol id="Result"></ol>
  <script>
    $("#Result").load("http://192.168.1.168/user/default.html #thatDiv");
  </script>
</body>

</html>

You can get the contents of the HTML file and find the starting "[[" and the ending "]]" and grab the data in between.

<?php
$serverBFile = "http://www.serverB.com/file.html";
$serverBHTML = file_get_contents($serverBFile);
$serverBStart = stripos($serverBHTML,"[[");
$serverBEnd = stripos($serverBHTML,"]]");
$serverBLength = $serverBEnd - $serverBStart;   
$serverBValue = substr($serverBHTML, $serverBStart, $serverBLength);
?>

The way that I have done this in the past is using DOM parsing tools like jQuery.

If you have access to a node.js server, you can use the jQuery plugin to load up server-B's webpage and then query something that's constant with the desired tag, be it ID, classname, tagname, location, etc.

<html>
<!-- Head information for the page including page title -->
<head>
<title>Test</title>
</head>
<body color=#FFFFFF>
<!-- Start of your page body -->
<!-- This code displays the current tag value for index 0
[[0]] will be replaced by the tag value a the time the page is loaded 
let's say [[0]] becomes a <div>-->
<div class="pink-box" id="thatDiv">data I want</div>
</body>
</html> 

From here, it's fairly easy to extract the text via $('#thatDiv').text() or $('.pink-box').text() .

This is a fairly simple solution. Once you get that value into a variable in your node server, just expose a REST call that your server-a webpage can make an AJAX request to.

The reason I say to use node is because it seems that this page has dynamic content that must be loaded with JavaScript. If I knew more about how this page interacted, I would be able to give more specific solutions to your problem,

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