-
Jul 14th, 2020, 04:39 AM
#1
Thread Starter
Lively Member
Import from another page
Hello
Please Help
Import a value from object a page
index.htm
HTML Code:
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<script>
function myimport() {
T2.value=T1.value//in page mm.htm;
}
</script>
<body>
<p align="center">
<object data="mm.htm" width="175" height="174">
</object></p>
<p align="center">
<input type="text" name="T2" size="20"></p>
</p>
<p align="center">
<input type="button" name="go" id="bn" value="import" onclick="myimport()">
</p>
</p>
</body>
</html>
mm.htm
HTML Code:
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<p align="center">
<input type="text" name="T1" size="20" value="OK"></p>
</p>
</body>
</html>
-
Jul 22nd, 2020, 10:55 PM
#2
Re: Import from another page
You could make a request to get the HTML of the separate web page, but there are some things to consider:
- If the separate web page exists on a different server, then you'll likely run into a cross-origin error
- If you expect the user to change the value on the separate web page, it wouldn't work unless you setup a JavaScript function to return the value
To summarize, if you need the predefined value of T1 on the separate web page and the separate web page resides on the same web page that the requesting web page resides on then it would work.
I'm not sure how it'd look in vanillla JavaScript, but in jQuery it'd look something like this:
Code:
function getInputValueFromSeparatePage(url, inputName) {
$.get(url, function(result){
const input = $(result).find(`input[name="${inputName}"]:first`);
return input.val();
});
}
-
Jul 26th, 2020, 11:01 PM
#3
Member
Re: Import from another page
With your scenario, I would solve by using localStorage.
On page1:
Code:
window.onload = function() {
var getInput = prompt("Hey type something here: ");
localStorage.setItem("storageName",getInput);
}
On page2:
Code:
window.onload = alert(localStorage.getItem("storageName"));
Hope it helps you!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|