473,383 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

store source code in a variable

83
Hi,

I can easily display the page source by simply calling

window.location = "view-source:http://www.example.com";

but how can i store the source code into a variable which i can work with.

I don;t want to use ajax as i will get the cross domain problem.

Thanks
Nov 22 '09 #1
2 2132
You could only do that yourself... possibly automatically (using SendKeys or using a .hta file extension locally), but you cannot create a website that does that (browsers know what zone the user is in)
Nov 24 '09 #2
Dormilich
8,658 Expert Mod 8TB
to work with such a page, wouldn’t it be easier to load that document?

once you have that it’s easy to get the source as string
Expand|Select|Wrap|Line Numbers
  1. // though the intended purpose of this is somewhat specialized…
  2. Element.prototype.getString = function()
  3. {
  4.     var tag = this.tagName;
  5.     var str = "<" + tag;
  6.     var atb = this.attributes;
  7.     for (var l, i=0, l=atb.length; i<l; i++) {
  8.         if (i in atb) {
  9.             str += " " + atb[i].name + '="' + atb[i].value + '"';
  10.         }
  11.     }
  12.     var cn  = this.childNodes;
  13.     if (0 == cn.length) {
  14.         return str + "/>";
  15.     } else {
  16.         str += ">";
  17.     }
  18.     for (var l, i=0, l=cn.length; i<l; i++) {
  19.         if (3 == cn[i].nodeType || 4 == cn[i].nodeType) {
  20.             if (String.trim) {
  21.                 str += cn[i].data.trim();
  22.             } else {
  23.                 str += cn[i].data;
  24.             }
  25.         }
  26.         else if (1 == cn[i].nodeType) {
  27.             str += cn[i].getString();
  28.         }
  29.     }
  30.     return str + "</" + tag + ">";
  31. }
Nov 24 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: F. Da Costa | last post by:
Hi, Does anybody know why IE5+ does *not* honour array objects (like a table) across a session? Example: Frame A contains a var tableVar which is set via form Frame B (on init) using...
8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
1
by: YoursTruly | last post by:
Hello, can anyone tell me how i can code the following: i want to store certain parsed data in variables. The data comes from a specific website. Can this be done with 'open'? var load =...
7
by: Alan Silver | last post by:
Hello, I am just looking at VWD and seeing what needs doing to take an existing site I've written by hand and importing it into VWD. I've already discovered that I need to rename my code-behind...
4
by: Rob | last post by:
Using VB.net and SQL server... I have a stored procedure that is simply returning a row count.... I know how to execute a stored procedure and add the output parameter. But how do I store...
4
by: wish | last post by:
Hi all, Where is the location for store session variable? Because i feel that the session variable is keep store the previous variable and no release the variable. When i click back button,...
2
by: rajeshjava | last post by:
I am working with xsl. i want to store a value in the variable. xml Source looks like the below one <?xml version="1.0" encoding="UTF-8" ?> <getTradingInstallmentHistoryResponse...
5
by: castironpi | last post by:
Hi, I've got an "in-place" memory manager that uses a disk-backed memory- mapped buffer. Among its possibilities are: storing variable-length strings and structures for persistence and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.