View Full Version : Getting values of H1 tag based on URL

05-29-2012, 06:28 PM
Below is the code I'm using.
Essentially I need the values stored within the H1 tag based on the URL, I don't know how to get that value or if it has to be scraped.

FYI the url needed to retrieve h1 tag data can be considered a cross domain.

Little guide on the mechanics of the form.

type model number in first box
second box retrieves the value within h1 tag
Image is shown based on which model number is typed in first box

Appreciate any and all kinds of help.
Thank You

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<form name="form1" method="post" action="">
<p>7-digit product#
<input type="text" name="model" id="model">
<label for="description">description</label>
<input type="text" name="description" id="description">
<input name="start" type="hidden" id="start" value="http://www.mysite.com/Products/">
<input name="end" type="hidden" id="end" value=".jpg">
<p><img name="proudctimage" src="=#start#model#end" width="32" height="32" alt=""></p>

var model_input = document.getElementById('model');
var start = document.getElementById('start');
var end = document.getElementById('end');
var image = document.getElementsByTagName('img');

model_input.onkeyup = function(e){
image[0].src = start.value + model_input.value + end.value; }


Old Pedant
05-29-2012, 10:20 PM
Can't do it. You can't cross-domain screen scrape using JavaScript. Oh, there are ways to do it *IF* you can put code into the pages on BOTH domains, but not if you have no control over the foreign domain's pages.

You *can* do this using server-side code: PHP/ASP/JSP/etc.

05-29-2012, 10:31 PM
if you're really set on client-side you could maybe do it using something like the yahoo ypl - which is the page you want to scrape and where is the H1?