Link Text To Another Page
Solution 1:
The first thing you need to know is that you need jQuery and more specifically its load()
function that lets you load data from other pages in the same domain onto another page
You need include the jQuery library like so:
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
You can use the jQuery.load()
function to get data from another page
$("#<parent div>").load(<content id>);
Here is a complete example of this:
index.html
<textarea id="myInput1" class="one" name="myInput1" readonly>
One
One
One
</textarea>
<p><a href='text.html'>link to next Page</a><p>
text.html:
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
<body>
<div id='content'>
</div>
<script>
$( "#content" ).load( "index.html #myInput1" )
</script>
</body>
Solution 2:
There are several steps to this.
First you need to make the text you pass to pass available to the page you are passing it to.
The traditional way is to encode this into the query string of the URL.
<a href="mypage?text=One">One</a>
Note that this is vulnerable to CSRF so if the target page supports arbitrary text then third-parties could link to your page and have whatever (e.g. offensive, fraudulent, or defamatory) content they like shown to the person who clicked the link unless you take steps to prevent that.
If you are working with purely client-side JavaScript then you might store it in localStorage instead. This, however, is subject to race conditions so if someone is clicking around multiple pages and going back to the page showing the link provided content then they'll get the text from thenlatest link that was clicked on, even if that as in another tab.
Second you need to read the data from wherever you put it. This question covers reading query string values using client side JS.
If you are using server-side JS then you are probably using Express, in which case you can use the request.query
property.
(The earlier link about localStorage shows how to read and write with it).
Third you need to insert it into the page. MDN has a guide for manipulating documents with client-side JS.
If doing this server-side then you should use a template engine that has suitable escaping features to protect against XSS.
Note that having lots of similar pages that differ only by small amounts of data is likely to give you duplicate content penalties.
Solution 3:
You want the page, e.g. index.html, to contain 3 links: one, two, three. After clicking on One it moved to, for example, one.html, and there was a link "return" from href "index.html"?
Manualy: <a href="one.html">One</a>
In one.html:
Manualy: <a href="index.html">Index</a>
Other
var element = document.getElementById(id);
In JavaScript.
Post a Comment for "Link Text To Another Page"