JavaScript - Getting Web Page Source
Hi,
i am very new to this place..so if i make nay mistakes, am sorry. and i am rookie at coding..so i may sound dumb... I wanted to know, if there is any method by which i can get the source code of a webpage in a program by using the URL. what i want to do is that am developing a javascript webpage which requires some info to be taken out of a certain webpage, and in the url of that webpage i can enter the query, so i wanted to know if there was any method to get the source of the webpage and store it in a varabile so i can scan it for the required info. Thanks. Similar TutorialsI am fairly new to JavaScript and I have been searching and searching and I cannot get a clear cut answer to my question. Here is what I am trying to accomplish: I want to gather the html source code from a particular sports score site and then store specifics of that resulting html (ie: the actual game scores) as strings, which I will then call in a windows sidebar gadget. Aside from actually getting the source code stored as a string, I would need to know how to then find a part of that string (ie: the text between "Last:" and "</") and store it as a separate variable. From what I have seen online I need to be using XMLHttpRequest... but I am completely lost when it comes to this. Can someone please give me a hand. Thanks in advanced. Please be as specific as possible. Dear all, I am trying to set up a web site for an art gallery. That is for new talents so I have no budget. I am not a web designer and I am facing some barriers. Maybe some of you could help me. My problem is, I guess, about going around with the DOM node tree. My page looks like this: FRAME 1 - Header FRAME 2 - Navigation bar FRAME 3 - Has arrows for scrolling iframe 3.1 ---- iframe 3.1 - has thumbnails FRAME 4 - First for query and after shows the enlarged pictures of thumbnails FRAME 5 - Has arrows for scrolling iframe 5.1 ---iframe 5.1 Has text explaining pictures in frame 4 How it works: In first place, after page has been loaded, I am using frame 4 to run a HTML form. After submit, iframe 3.1 is populated with thumbnails according to the query. When a thumbnail is clicked, I succeeded in bringing the corresponding text, talking about the artwork, on iframe 5.1 to do so, I change the html source in iframe 5.1 I am using for that: top.frames['frame5_id'].document.getElementById('iframe 5.1_id').src=new_source.html; The idea was about doing the same with the frame 4 that is for a larger picture of the artwork. But first I need to get rid of the form once it was submitted (bring a new HTML with a dummy transparent gif to be swapped with the desired picture). But how can I bring a new html in frame 4? After the form is submitted the 'action' moves to iframe 3.1 I tried changing the html source using getElementById but I could not find a way to get to the right object. So my questions a Two src attibutes must be changed with code written in iframe 3.1. (where the thumbnails are clicked). But... How can I address and change the HTML src code in FRAME 4 ? How can I address and change the src image in the new code loaded in FRAME 4 ? I have both attributes in variables but don't know how to get to the target elements Thanks for any help. regards, wagner This is my first post on this website. It has a very clean design to it. I think I am going to enjoy myself here :P I am taking a class. And I am very sorry if this post does not belong here. It is a JavaScript class so, my guess was here. My professor has giving us three page sources from random sites. I can not figure this out though. This question has a page source from some random math test website. What we are to do with this page source is to figure out the ten correct answers to the question in the page source. No, not by doing the math, but figuring out where in the page source it is hiding. I can not find them for the life of me. I got the other two problems, but of course this is the hardest one Thank you for your help I put the page source in a notepad attach to this post. (My professor has removed parts of codes that included the name of the website he had gotten it off of. He also said the page source may need to be decoded.) I think I found what I am looking for. If you look where question one starts. Itll have <input type="hidden" name="corAns" value="27478035"> But, the answers are A, B, C, and D which would be 1, 2, 3, and 4 for D. So is <input type="hidden" name="numAns" value="4"> The correct line? I think that is to easier. He said this assignment was the hardest out of the three, and well, that was to easy? I know that when you "display: none" with CSS it will not show the div content in the browser, but will still show the div and content in page source. Is there a way (via javascript or anything else) to also remove the content from page source at the same time? Thanks. I have created and opened a new window using Javascript and written to it with the document.write Command. When I click "View" and then "Page Source" (Firefox) to view the source of it, however, it displays a blank page. How can I get the source of a window I created? Thank You Charles Im very new to java scripting so any help would be truly appreciated. I have a single web page that loads several iframes. One of the iframe pages has to be logged in first. I have that taken care of but once the page is loaded I need to change the source to a link with in the page. My guess is I need something to execute the code like a onload or something. This is what Ive been trying to get to work but like I said a newb! The iframe in question is named "cad" the initial source once loaded is 'https://urlname.com/mainmenu.asp' the source I need to change to is 'https://urlname.com/UnitStatusF.asp?agency_id=28' [CODE] function ChangesSrc() { var iframeid = document.getElementById(cad); var unitstatus = 'https://urlname.com/UnitStatusF.asp?agency_id=28' if (iframeid.src = 'https://urlname.com/mainmenu.asp') iframeid.src = unitstaus; return false; } [[CODE] recently i noticed that all of my embedded JavaScript code and external style sheets are being shown IN "view source." this happens in all browsers ( IE, FF, Chrome, and Safari [windows]) ... oddly enough it only happens when viewing on my vista or win2k3 machines. is this something added to these OS's or the result of an installed program? has anyone seen this before? Very new to Javascript (been a HTML/CSS guy for a while, but never really got into more than tinkering with other other people's Javascript coding), but I came across a situation I can't find canned coding for, and trying to create it from bits and pieces I Googled has led me to a dead-end. In summary, I have a website that I frequently visit (FWIW, Firefox 3.x is my browser of choice) with many image sources referring to URLs that end with "-thumbnail.jpg". However, for better image quality, I am trying to use Greasemonkey to replace all instances of "-thumbnail.jpg" in the source of images on this site with "-bigthumbnail.jpg". The closest I could think of was to somehow use getElementsByTagName and innerHTML.replace, but realized that innerHTML does not do HTML, only content. Below is as far as I tried to get on my own, I appreciate any assistance from the folks here to help a JS novice like myself, thanks! Code: (function() { var as,ae; as = document.getElementsByTagName("img"); for (var i = 0; i < as.length; i++) { ae = as[i]; ae.innerHTML = ae.innerHTML.replace(/-thumbnail/gi, "-bigthumbnail"); } })(); Hi, I would like to ask if there is anyway to get a variable from any webpage source using javascript. Something like javascript: document.getelement? hi- trying to set frame source from javascript- i cant get it to work.. Code: <script> stud = mm_adl_API.LMSGetValue("cmi.core.student_id"); newlink = ('https://blah.blah.blah&stud_id='+stud); // --> </script> <frameset rows="*,80" frameborder="no" border="0" framespacing="0"> <frame src="javascript:window.location(this.newlink)" name="thisname" /> <frame src="bottom.html" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" title="Scorm Handling" onload="mm_adlOnload()" /> </frameset> I am trying to use an external source for my javascript. The source loads with my script but the functions from the external source are not working. I do have it saved as a js file and in the same folder as my assignment. Below is my external source I am trying to use: <html> <body> <script type="text/javascript"> // Convert miles ==> kilometers function milesToKilos(miles) { return miles * 1.609; } // Convert kilometers ==> miles function kilosToMiles(kilos) { return kilos * 0.621; } // Convert miles ==> yards function milesToYards(miles) { return miles * 1760; } // Convert yards ==> miles function yardsToMiles(yards) { return yards * 0.0005682; } // Convert Fahrenheit ==> Celsius function fahrToCels(fahr) { return 5.0/9.0 * (fahr - 32); } // Convert Celsius ==> Fahrenheit function celsToFahr(cels) { return 9.0/5.0 * cels + 32; } // Convert Pounds ==> Kilograms function poundsToKilograms(lbs) { return 0.4536*lbs; } // Convert Kilograms ==> Pounds function kilogramsToPounds(kg) { return kg/0.4536; } </script> </body> </html> Now here is the javascript I am trying to use to run the external source. I can enter information but it is not using the functions from the external source. <html> <center><h2>Conversions</h2></center> <head> <script type="text/javascript" src="conversions.js"></script> </head> <body> <script type="text/javascript"> lbs = prompt ("Enter kilograms to convert", " "); var myFirstVariable ; myFirstVarible = "lbs"; alert (lbs) ; kg = prompt ("Enter pounds to convert", " "); var mySecVariable ; mySecVariable = "kg" ; alert (kg) ; </script> </body> </html> I am currently trying to write a javascript function which checks whether the source of an image is one thing, if so do this, if not do something else. Any help is much appreciated. Below is the code I have tried... Code: if(document.getElementById("field").src == "images/tick.png"){ alert("this is the tick image"); } Is it possible to self source a javascript file? I have a file with code that opens a javascript window and document.writes to it. I want to run some code in this file attached to window.onload. Code: function someWindow() { var openedWindow = open(/* relevant vars */); openedWindow.document.write(/*doctype and html head markup*/) openedWindow.document.write("<script type=\"text/javascript\" src=\"(this file)\"></script>"); openedWindow.document.write("<script type=\"text/javascript\">window.onload = function(){ /* sourced code */}</script>") openedWindow.document.write(/*html body markup*/) openedWindow.document.close(); } then in the same file have code defining object constructors and such that attach events to various elements. I realize I can write a long string variable with all the code, but that would be visible a browser window -> view source window ( I know it won't hide the code in a separate source file) The object is to have a widget all in one file, rather than having a separate html, css file and another javascript code file. Thanks for advice, suggestions, encouragement, JK Hey. I've been trying to get this page working with dynamically loaded iframe sources passed by URL, but I can't seem to get it working. Here's the relavent code: Code: <script type="text/javascript"> function delineate(str) { URL = str.indexOf("=") + 1; return(str.substring(URL)) } </script> Then there's a form/submit button that simply return the name of a type of item, for example "german" or "french" Using the form attributes method="link" and action="pageURL.html", where pageURL is the page that all of this is on. Code: <form name="hack"><input type="hidden" name="selector" /></form> <script language="javascript"> var url=window.location; document.hack.selector.value=url; var url_select=document.hack.selector.value; var selectedURL="../types/" +delineate(url_select) +".html"; document.write (selectedURL); frames['middleframe'].location.href=selectedURL; </script> <iframe id="middleframe" name="middleframe" src="../types/default.html" width="100%" scrolling="auto" height="1000" frameborder="0" style="display: inline;" /> I used the hidden form to change the url to text - advice from another website. I'm sure there are better ways to do it, but I'll explore them as soon as this thing actually works.. The types are in a subfolder named types, as shown. The document.write was placed in as a debug helper, and it displays the proper file location of whatever I select with the combo box, but the iframe doesn't change it's src to the selected page! I've tired the last line of the last <script> with several different methods, none of them producing any effect whatsoever. What am I doing incorrectly? Any help? Thanks. What is the code to stop people from viewing your source. Such as this site: http://bad-behavior.com (View The Source of That Site) I've searched the forums, and all I got was a bunch of "nothing can protect your source" I don't care about all of that. I want the code because: 1. Most people don't know how to view a source after it has been blocked 2. I think it's cool I want to hide my JavaScript but when I checked the FAQ of this forum, I saw that it said that it isn't possible. But how did worldometers.info did it? Because I cant find the JavaScript source. Hi , I made a table that retrieves some Data from the Database also I did some calculations for this data using Javascript and It works fine , but I can't see the calculated values in the source code . That's the Problem , cause I can't print it or export it without these values. and the source code doesnt show it... so , what can I do , to view the generated values from JS in the source code ?? Thanks , I'm afraid this is a task related to my job and I need ur Help Urgently I'm using IE 6 only as a web browser and the Javascript Calculations are functions and Classes in a seperated file and I linked it to the Report page ... I want to be able to display an embedded video on a web page but i want the URL to be different based on the source IP visting the web page. Can this be done in javascript? Example: If someone from inside our network (one IP address on the outside) visits our external web page (hosted externally) visits a web page with one of the embedded videos the URL and code will serve up a locally hosted video. (WMV format) If someone outside our network (any other IP) visits our web site, they'll see embedded videos hosted on YouTube. Hi, I try to change script source dynamically. When I use the following code, it works fine, and the script is executed Code: <script type="text/javascript"> document.write('<script src="http://gamestoenjoy.com/site/test.php"'); </script> However when I use the following code, it doesn't work, the script isn't executed Code: <script type="text/javascript"> var url = "http://gamestoenjoy.com/site/test.php"; document.write('<script src=url>'); </script> The only difference between the codes is that in the first code I use constant sting, and in the second code I use variable, in order to make the source dynamic. Please help me to solve this problem. I cannot get this function to work properly. Any help would be appreciated, please understand i am not so good at scripting i am trying to check the source of multiple images in one if statement to run a sound. Code: function victory() { if (document.getElementById("Image0").src == "0.jpg" + document.getElementById("Image1").src == "1.jpg" + document.getElementById("Image2").src == "2.jpg" + document.getElementById("Image3").src == "3.jpg" + document.getElementById("Image4").src == "4.jpg" + document.getElementById("Image5").src == "5.jpg" + document.getElementById("Image6").src == "6.jpg" + document.getElementById("Image7").src == "7.jpg" + document.getElementById("Image8").src == "8.jpg" + document.getElementById("Image9").src == "9.jpg") { document.getElementById("vic").currentTime = 0; document.getElementById("vic").play(); } else{ } } Reply With Quote 01-21-2015, 05:19 PM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts + is the addition, concatenation and number casting operator. the logical AND operator is &&. cf. https://developer.mozilla.org/en-US/..._and_Operators |