![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,549
|
Question for javascript gurus
Hello, I love you.
I have an HTML page with some basic data with only 2 or 3 fields: This, That, and the other thing. I want to display that data on another HTML page, but I don't want to use iframes. Instead I want to grab the data from the first page and display it on my main page with styles associated with that page. Any suggestion?
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Industry Role:
Join Date: Mar 2002
Posts: 8,234
|
How are the fields being retrieved from the first page? Just static HTML? Or is it pulling the data from somewhere like through js?
If it's not pulling the data from somewhere or some API, you'd need to scrape the data. There's a lot of different techs you can use to scrape. Python is the most popular. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
AJAX/JSON on both pages to a server side script.
Cross domain will require good scripting. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
StraightBro
Industry Role:
Join Date: Aug 2003
Location: Monarch Beach, CA USA
Posts: 56,232
|
^^ This man is verified as super brains
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
I am thinking you want to use sessionStorage for that.
https://developer.mozilla.org/en-US/...sessionStorage Quote:
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Here is a working example: http://madspiders.com/js_test/page1.htm
On Page 1 enter something in the text box and then hit the link to page 2. On page 2, whatever you entered on page 1 will be displayed. Code for Page 1: Code:
<html> <head> <title></title> <script type=text/javascript> function storeit(stored_data) { sessionStorage.setItem('stored_data', stored_data); } </script> </head> <body> Enter something here: <input type=text value='' width=20 maxlength=50 onChange="storeit(this.value)";><br> <a href=page2.htm>Go to Page 2</a> </body> </html> Code:
<html> <head> <title></title> <script type=text/javascript> function get_data() { var stored_data = sessionStorage.getItem('stored_data'); if(stored_data>'') { result_div.innerHTML='data stored was: ' + stored_data + '<br>'; } else { result_div.innerHTML='no data was found<br>'; } } </script> </head> <body> <div name=result_div id=result_div> </div> </body> <script type=text/javascript> get_data(); </script> </html>
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Too lazy to set a custom title
Join Date: Mar 2002
Location: Australia
Posts: 17,393
|
Not sure about sessionStorage, but I'm pretty sure that most browsers will prompt the user for confirmation (ie, a dialog saying "this site wants to...") when the code uses localStorage. Test carefully to make sure you don't spook your visitors.
Edit: Also this text seems to suggest you can't share data between windows, because they will be considered separate sessions. "Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
StraightBro
Industry Role:
Join Date: Aug 2003
Location: Monarch Beach, CA USA
Posts: 56,232
|
Quote:
^^ Verified super brains much respect ^^ |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
♦ Web Developer ♦
Industry Role:
Join Date: May 2005
Location: Full-Stack Developer
Posts: 12,469
|
I'd use AJAX for that.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
I also just added a second link on page1 to open page 2 in a new window and the data passes between them just fine. Tested that in Chrome and FF. So this is the simple, easy way to accomplish the task as far as I can tell. I like simple solutions as I am a simple minded person. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,549
|
Hi Everyone,
Let me clarify a little. Both pages are HTML. My main, fancy html5/css3 sexy page, index.html, would say "Hey! Here's the data! 1&2, 3&4, 5&6. " The page that actually contains the data would be unformatted nothingness, called "data.html", and would just contain "1&2", "3&4", "5&6". Both pages are HTML, and both are on the same domain.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Too lazy to set a custom title
Join Date: Mar 2002
Location: Australia
Posts: 17,393
|
So you're saying you want the main HTML page to fetch another page/object which contains raw data... that's an AJAX callback.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
Where is the data page coming from. If it is displayed in the browser then is it displayed before the fancy page is displayed? In which case, why? Anyway, here is how you could do that using Ajax (JQuery version): Ajax version at: http://madspiders.com/js_test/ajax_page1.htm Code:
<html> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> </head> <body> <div name=result_div id=result_div></div> </body> <script> $.ajax({url: "data.htm", success: function(result) { $("#result_div").html("The data is: " + result); } }); </script> </html> Code:
1&2, 3&4, 5&6
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Confirmed User
Industry Role:
Join Date: Sep 2015
Posts: 1,045
|
Just like to add. If "data.html" is made up of user supplied data, make sure you filter the data so that you only get data.
To avoid problems like persistent XSS, LFI (local file inclusion), and RCE (remote code execution).
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
For cross domain I just found this
enable cross-origin resource sharing https://manning-content.s3.amazonaws.../CORS_ch01.pdf This is interesting. It's OK for free content because your API Key is in plaintext in the .js file -- Facebook and the like ... You could also watermark your public images and make them available for wide distribution. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Bump to see if this took care of Mark or not.
.
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |