![]() |
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? |
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. |
AJAX/JSON on both pages to a server side script.
Cross domain will require good scripting. |
^^ This man is verified as super brains :thumbsup
|
I am thinking you want to use sessionStorage for that.
https://developer.mozilla.org/en-US/...sessionStorage Quote:
|
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> Code:
<html> |
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." |
Quote:
^^ Verified super brains much respect ^^ |
I'd use AJAX for that.
|
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. . |
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. |
So you're saying you want the main HTML page to fetch another page/object which contains raw data... that's an AJAX callback.
|
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> Code:
1&2, |
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). |
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. |
Bump to see if this took care of Mark or not.
. |
All times are GMT -7. The time now is 02:15 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc